Charge Credit Card With C#

Hello Fellow Unity-ers!
I am currently working on creating a game and I need to integrate in-app-purchasing. Now, obviously there is the Unity IAP, but unfortunately, that is not available until Unity 5.3.0, and I, due to the inability to currently upgrade my computer, do not have the access to the IAP service. All I’m really looking for is a simple script that can ask the user for credit card info, then, using that info, charge the user a set amount of money depending on what the product costs. Thank you all in advance for helping out with this post.

  • tiger27

if you want this to be secure I doubt it’s going to be “simple”… this is where frameworks like Unity IAP come in, they simplify the code you have to write by doing all the hardwork for you. If you can’t use that specific framework due to version issues I highly recommend finding another one that does work with your version (there were IAPs in use before Unity IAP after all).

5 Likes

You could set it up through paypal and php scripts quite easily. Did it for my first game (non-unity) in a couple of hours. It’s pretty easy to have unity run a php script and get results.

I’d also suggest PayPal.

Otherwise, to submit a charge, you need something called a merchant gateway account – a third party who acts as an intermediary between your company and the various credit card companies. You have to be a pretty large company before the card companies will allow you to go direct. Typically those merchant gateways require you to either display their content (e.g. your users actually enter their information into a web page supplied by the gateway) or to use some other approved service (salesforce, for example). If you’re a sufficiently high-volume customer, many merchants will help you build your own entry method – but if you’re asking these questions, you probably aren’t in that category.

PayPal will cost you more per transaction, but the effort is likely lower. If you decide to try the merchant gateway route, shop around, prices can vary significantly.

1 Like

So it probably looks as though I’ll be using PayPal, however, I couldn’t really understand how to integrate PayPal into my project. Do either of you have any tutorials, or know where I can find some?

Quick google search returned http://www.evoluted.net/thinktank/web-development/paypal-php-integration and https://devtools-paypal.com/guide/pay_paypal/dotnet?interactive=OFF&env=sandbox

Just to re-iterate what was shared before. Getting PayPal up and running, you can leverage developer accounts with them for testing - and you’ll need to really work out your own WWW WebForm or PHP system. Just be very cautious, espcially if you are planning on using any kind of third-party server (such as your own).

The code you write in Unity can be very very easily decompiled, and a hacker that thinks you are using a custom payment system will be able to see anything you coded including endpoints, salts, certs or keys.

1 Like

So, Just To Make Sure I Got This Totally Correct:
I’m going to set up the PHP on my company website, and then am I going to just go to the page with the form on it through an Application.OpenURL? Or does this somehow integrate into my app?

I’m going to take back everything I wrote and just +1 this recommendation.

Security is likely the most difficult part of software development to do correctly.

Your best bet is to find something professionally built when it comes to handling other people’s credit cards.

1 Like

Unless you really know what you’re doing, I would HIGHLY not recommend making custom code to process credit card numbers. As a user has already written, the code in Unity can be very easily decompiled. All you have to do is install Dotpeek and look into the Assembly-CSharp.dll file. Yes, I’ve done it myself on my own projects. A hacker could easily view your code (in less than 30 seconds of work) and create a method to steal your customer’s info. Then that could backlash and you could even be hit with a lawsuit for not protecting personal information properly.

While you could try to use PayPal, I’m not so sure how easy it would be to implement such a system. I guess you could have an in-game browser, but then the user would have to fill out a form which might discourage people from purchasing goods.

I really don’t see why you can’t get Unity IAP to work. I’ve gotten IAP to work and I’m not even that good at scripting. Instead of taking giant risks to avoid using Unity IAP, just figure out your computer issues (or whatever is stopping you from upgrading) and use Unity’s IAP.

That’s just my 2 cents, I’m sure I wrote something stupid.

1 Like

If you are going down the PayPal route, your best bet will be to simply direct the user out of the game and into a regular web browser to handle the transaction.

3 Likes

I believe that BoredMormon is right, doing it through the web is probably the best bet, since: 1. The internet’s more secure and 2. I don’t have to perform the credit card charging myself. I’m going to try putting a paypal form on my website, and see what happens. Cross your fingers!

Here’s the list of rules for handling credit/debit card transactions:

Read them all. Then forget about the idea and use a merchant gateway :slight_smile:

If you really can’t make the regular IAP system work, PayPal have their own SDK:
https://github.com/paypal/sdk-packages/tree/gh-pages/MPL

iOS instructions
Android instructions
Windows phone? You’re screwed.

@orb Since I would rather just have the IAP in the actual app, and not make it go to the web to process the payment, I am going to try doing it your way. However, I’ve hit a roadblock. Does anyone know how to modify the android app’s manifest file? Thanks in advance!