In-app purchase with server

I want to implement a purchase mechanism in an application that supports both Google checkout and PayPal for buying virtual items in one of my Android apps. I have read both links to these mechanisms, but I still have one question regarding how to handle such purchases correctly. The problem is that I would like to manage the call to my server as part of the purchase transaction and in case the call does not cancel / rollback the entire transaction. If I first complete a purchase transaction and only when it confirms, I call my service, what should I do if it does not work? If I call my service first and try to process the transaction and it doesn’t work, I need to cancel my call (and what happens if the rollback fails?)

What is the right way to manage it? Is there a way to create a multiphase transaction that I am missing?

+6
source share
4 answers

Try using the Google Checkout mechanism provided for InApp Billing than the PayPal SDK, as this is the best way to get answers about transaction errors, as well as RESTORE TRANSACTIONS , if the application was removed from the device and reinstalled again. Google provides asynchronous broadcast notifications during transactions with billing applications. Types of purchases can be divided into Managed (for each user account) and UnManaged.

Google provides information here: In the app invoice overview , as shown below:

1. Some billing implementations in the application may also use a private remote server to deliver content or verify transactions, but the remote server is not required to implement billing in the application.

2. A remote server can be useful if you sell digital content that must be delivered to a user device, such as media files or photos.

3.You can also use a remote server to store user transaction history or perform various billing security tasks in the application, such as signing verification.

4. Although you can handle all security-related tasks in your application, it is recommended that you perform these tasks on a remote server, as this helps make your application less vulnerable to security attacks.

So, in conclusion, I would like to recommend you the implementation of Google InApp billing compared to other third-party payment processes.

+5
source

I have never used Google Checkout before, only PayPal.

What you might be looking for is the PayPal Payments Pro SDK.

This allows your server to become the face of a payment transaction (and not a PayPal site, like a regular express train).

You need to implement a two-phase fixation mechanism.

I can recommend two different approaches:

a) You can start the purchase process on your server and leave it in the average “undeveloped” state in the database. You call PayPal from your server so that PP can handle your call, and when you have a response from PP, and if the answer means that the payment has been accepted, you make a purchase. The problem with this approach is that your application must decide whether to complete or refuse the transaction at that moment, and that’s not how the transaction in the real world can behave. PayPal may sometimes respond to something other than just OK / Error, payment may be delayed or may be in order with a warning.

b) PayPal provides payment status notifications even more reliable.

You are doing the same thread as before, with the change. As soon as PayPal processes the payment and gives you a positive answer, you save the transaction identifier in your database, but do nothing. Only inform the user that the transaction has completed.

As part of the PayPal server call, there is a parameter that you can use, this parameter is called the IPN listener URL.

IPN stands for “Immediate Payment Notification”, it is a return to your server created by PayPal, in which your application will receive instant information about your payment status.

This is really important, as pending transactions can be accepted or rejected. Even a accepted transaction can be rejected by you or at the request of your buyer at PayPal.

Let me know if you need more information on how to implement a PP IPN receiver.

+3
source

If you are still looking for a way to implement the payment method processed by Google, you can find a detailed description of how to implement the Android Market In-app Billing here:

http://developer.android.com/guide/market/billing/index.html

+3
source

AFAIK, a rollback transaction is not possible. I think the logic of Google is as simple as possible: if you have a product (added to the developer's console) than you can sell it.
When Google Marketing informs you PURCHASE_STATE_CHANGED, you must confirm the transaction. Otherwise, the application will receive PURCHASE_STATE_CHANGED until it is confirmed, but the fact is that the user is already charged. And you cannot cancel this transaction.
If your server can reject the transaction, you must implement additional logic for such cases, for example:

  • check if the product is available before the purchase;
  • if the product is available - use the "reservation" so that the product is sure that it exists upon purchase;
  • etc.;
  • Otherwise, you must tell the user to contact support for a refund.
0
source

Source: https://habr.com/ru/post/916371/


All Articles