How to configure in-store products

Pit 1: Project and price configuration

There is a big difference between apple’s in-app purchase payment and alipay or wechat Pay.

  1. The price of apple in-app purchase can only be selected, not directly set. As shown in figure:

2. Apple In-app purchase payment is implemented by configuring the project mode. We should think of each project as a product configured on Apple’s backend, not just a payment configuration. So it’s a little bit easier to understand.

  1. There are many types of projects, each of which serves a different purpose and can even influence the review

  2. After configuring a project for the first time, you need to re-introduce a version before it takes effect. So, the sandbox test is the first one.

Pit 2: In-purchase item type

  1. Consumable goods

Items that can be consumed, such as in-game gold, diamonds, etc., can be used to buy in-game virtual items.

  1. Non-consumable goods

Items that cannot be consumed, such as courses in some educational apps, or track in some racing games, need to be added to the purchase recovery button in the review, which is used for the recovery process after the user mistakenly deletes the APP or undeletes the APP for other reasons. Otherwise, the submission for review will be rejected.

  1. Non-renewed subscriptions

These items are similar to consumable items, such as one-month membership, one-quarter membership, etc., but differ from consumable items in that they require a shared secret key to be passed in order to verify the certificate

  1. Automatically renew subscriptions

The process for this type of product is slightly different from other products, such as continuous monthly membership in a video APP. When such products expire, the fees will be automatically deducted, and the server verification logic will be different

The most popular type in China is consumable goods, and we usually handle the payment logic through our own server. There is some additional logic that needs to be processed with subscription type items.

Note: All consumable goods need to implement”Return to buy“Function, otherwise it will not pass the audit.

Consumable payment process

Pit 3: Processing of apple internal purchase omission

  • There is one big difference between the in-app Purchase and wechat/Alipay payment processes.

The result of wechat/Alipay payment is called back to its own server via notify_URL. In this way, the user can greatly ensure the success of the payment, the background is able to accept the payment results. However, after apple in-app purchase payment succeeds, the client still needs to request the authentication interface of the server, and the payment can be judged to be valid only after the authentication succeeds. In this process, it is easy to miss orders because of problems such as network flash back.

  • Processing of missing single case

For the above analysis, we need to let the background generate an order before the purchase. After knowing that Apple paid successfully, save the order and the verification data returned by Apple to the local. Finally, the backend interface is requested for verification, and the local verification data is deleted after the verification is passed. If not, it will be verified automatically when you open the APP next time.

Pit 4: Sandbox testing is the only way to test, even on TestFlight

Say not very pit, just can’t through the development of actual payment to test, let a person in the mind. The actual test will be tested after the launch, and if there is a problem, it can only be revised with a new version. But the consolation is that there’s no problem in the sandbox and there’s generally no problem online.

Pit 5: Actual payment test

Because apple charges a 30% commission for in-app purchases. Then the actual payment test cannot be paid with the actual amount of the product. Only 1 yuan of goods can be configured for testing. The problem is that for small payments, Apple’s delay can be large. We’ve had three payments in a row, and the purchase is successful. Nevertheless bound pay treasure does not have to deduct money to remind. I thought I missed the deduction, but it took hours.

Use of the Flutter Apple in-app purchase component Flutter_InAPP_Purchase

  1. Download the dependent
Flutter_inapp_purchase: ^ 3.0.1Copy the code
  1. Initialize components and listeners
var result = await FlutterInappPurchase.instance.initConnection; / / set the result to monitor/buying/update subscription _purchaseUpdatedSubscription = FlutterInappPurchase. PurchaseUpdated. Listen ((productItem) { print('purchase-updated: $productItem'); if(productItem.transactionStateIOS == TransactionState.purchased) { //todo }else{ closeProgressDialog(); }}); . / / buy error subscribe message _purchaseErrorSubscription = FlutterInappPurchase purchaseError. Listen ((purchaseError) { print('purchase-error: $purchaseError'); closeProgressDialog(); });Copy the code
  1. Get the list of items on the Apple server, even if it is not available, get it once before payment, otherwise payment will fail.
List<IAPItem> items = 
await FlutterInappPurchase.instance.getProducts( ['0001', '0002', '0003'] );
Copy the code
  1. Pull up Apple Pay
Var result = FlutterInappPurchase. Instance. RequestPurchase (' 0001 ');Copy the code
  1. Get a list of consumable items that need to be “restored to buy.
List<PurchasedItem> items = 
await FlutterInappPurchase.instance.getAvailablePurchases();
Copy the code

If you are creating consumable goods, this is the usual approach.

conclusion

There’s nothing complicated about in-app purchases, but a lot of the features are baffling to first-time users. But when you figure it out, you’ll see.

So, this article is not a detailed tutorial, but just a few pitfalls and some understanding of Apple Pay. However, I’m sure after you read this article, it will be much easier for you to make an in-app purchase.