[Transfer to]ios in-app payment (IAP) Development steps

Source: Internet
Author: User

from:http://blog.csdn.net/xiaoxiangzhu660810/article/details/17434907

Reference article Links:

(1) http://mobile.51cto.com/iphone-389249.htm

(2) http://blog.csdn.net/xiaominghimi/article/details/6937097

(3) http://zengwu3915.blog.163.com/blog/static/2783489720137485857701/

The steps are as follows:

The first step: you need to create a new app in Itunesconnect, and then set up some products (pay props) for the app;

OK, here Himi a little explanation, Itunesconnect is a platform provided by Apple, mainly provides AP publishing and management app, the most important function is to create management project information, Project paid products (props) management, paid test account, submit app and so on, here is a brief introduction to so many , the word "product" can be understood as a game prop; in Apple's opinion, all the payments are part of the product. = Don't tangle with words oh ~

OK, open Itunesconnect website: HTTPS://ITUNESCONNECT.APPLE.COM/WEBOBJECTS/ITUNESCONNECT.WOA (note: Enterprise-level users must use the company's main developer account to log in!) )

After the successful landing page is as follows:

Here's about something important:

contracts, tax, and Banking: Manage bank accounts, contacts and taxes, etc. here to complete the corresponding information according to the prompts to fill in! Be sure to fill in the details Oh ~

Manage Users: Manage the user, such as the master account and test the paid (test app) account;

Manage Your applictions: Managing applications, all of your published apps and the status of each app are here;

Below we create a new app project, we can rest assured that we have created here is not directly submitted to the app audit, so rest assured to create, as long as the control of the state of the app is not to be audited, but even if you accidentally submitted the project, also nothing, directly change the app state can be;

Select the Manage Your applictions option, and then create a new project: "Add new App", fill it out according to the prompts, it is not detailed here ~

After you create the good one app, the interface after clicking Manage Your applictions should look like this:

Here you will see the app you created, click on the app you created, here Himi create the project name "Projectforbuytest", click on your app to enter the following screen:

 

(Note: The bundle ID here must be consistent with the bundle ID in your project Info.plist!!!!) )

Here we can manage your project's information, status, embed Gamecenter and so on, so this chapter focuses on how to use the IAP sandbox to pay for in-app, so here we click on the "Manage in-app Purchases" in the top right corner. The option to enter the Create product (game props) interface is as follows:

below to see Himi created four products (props), you can click on the "Create new" option to create a new product (pay props), click the new screen as follows:

Himi does not have all the options, here is about the introduction, this interface is to choose the type of your consumer items, the types described below:

There are four choices of type selection:

1.Consumable (consumable): Each download requires a fee;

2.non-consumable (non-consumable): Only one payment is required;

3.auto-renewable subscriptions: Automatic subscription;

4.Free Subscription: Free Subscription

The bottom is you sandbox test, for the moment, no matter;

Here Himi choose the consumable option, for example, many games are purchased coins, this way you can choose this, and then appear the following interface:

Reference Name: Reference name for paid products (props)

Product ID: The unique ID of your product. The usual format is com.xx.yy, but it can be any form and does not require a program's app ID as a prefix.

Add Language: Added product name and description language;

Price Tier: Select Prices, where you select the price, will appear as the bottom of the price table

Screenshot (screenshot): Display the screenshot of your product. (This is a direct disregard, the test app must take care of this)

Product ID can create more than one, for example, I think the game is divided into 0.99$, 1.99$ and other props that create a corresponding product ID!

After we have completed the "Reference Name" and "Product ID" and "Price Tier", click on the "Add Language" option and then the following interface appears:

The options in:

Language: Language

Displayed name (display name): The product name that the user sees.

Description (description): Describe the product.

OK, save all the way back to the "Manage in-app Purchases" interface to see our new product (props) as follows:

You can see the new product (item) ID: Here Himi created the Product ID is Com.himi.wahaha, here to remember this Product ID OH ~

The second step: Apply for test account, using sandbox test simulation appstore purchase props process;

go back to the Itunesconnect home page, select "Manage Users" and then select "Test User" and the interface appears as:

Here Himi has created two test accounts, click on the interface of "ADD new User" To create, remember the account and password ha, remember to delete the new Wahaha ~ (remember: Can not be used in real appstore in this account, not only can not use, And once AppStore discover the consequences you know ~)

The third step: fill in the relevant tax, bank, contact information;

1. It needs to be set up first. Click "Request", fill in the basic information of legal entity   after completion agree to an agreement and submit the page will appear contracts in process. 2. Then, to set the contact Info, the tax Info and bank info (1), contact click "Set up" under Contact Info, go to the Contact information page and click "Add New Contact" to add new contact  Fill in the corresponding information, point save Save can   then go back to the Contact information page, just add the contact will appear in the dropdown box, the corresponding role set corresponding contact and then point done   (2), bank back to contracts, tax, and Banking main page, select "Set up" under Bank info to enter the bank information page. Select "Add bank Account" to add a bank information   Select the country where you open your bank card, here is China, hehe    next set up the bank's Cnaps Code, which is said to have a number of lines, Can be understood as the unique ID of each bank branch, this can be called to ask you bank card banks, is their one of the only 12-digit identification number, you can also search by Apple's look up Transit numbers.    However, I think Apple's search in English, do not know what the English name of the domestic bank, what branch of English is what. OK, then use the following site to query is also possible https://e.czbank.com/CORPORBANK/WebBank?&tranFlag=0&dse_operationName= wgqueryunionbanksrvop  copy gets the modern payment system line number that sticks to the Cnaps code entry on the Apple page above. Click Next, Apple will read the corresponding bank information according to the code you wrote, and you can verify that the bank number you wrote is correct.    next step to set your card number, account name and currency (RMB is CNY, originally thought is RMB, looked for half a day, wondering.) Of course, if your card supports dollars or whatever, you can choose a different currency)  

After this step is set up to display all the information you set, which you can check whether it is wrong, ask no question, click "Save" Save, save it back to the front of the Choose Bank page, select just set up the bank "save" to complete the bank setup (3), Tex back to contracts, tax, and Banking main page, select "Set up" below Tex info and go to the Tex information page. If there is a country in which you are elected, none of them chooses U.S. Tax Forms. Here's how to set up the situation in the Celestial state: A. Select the first U.S. tax Forms, click on the "Set up" B below. Whether a U.S. citizen, or a U.S. company or something, this choice "No" will be OK, or you will have to set the VAT number, this, the real wood has. C. There is no American business activity. This also uses "No", this god horse is too far away, hehe
D. Set up tax infomation. Set the basic information set after the point "Confirm" on the completion of the same, the world also set. A processing time will be required after the setting is complete, and the theoretical value will be completed within 24 hours.

Fourth step: Apply for product code and monitoring in the project;

First, development work (iOS side)

1. Introduction of Storekit.framework and #import <StoreKit/StoreKit.h> in engineering

2. Get a list of all paid product IDs. This can be stored locally on a constant, or returned by its own server.

3. Create an interface to show all in-app paid items. The price and introductory information for these in-app paid items can be returned by your own server. However, if it is a standalone game app or tool class app without a server, it can be obtained by querying the App Store. When I was testing, I found that it was very slow to query the App Store, which usually takes 2-3 seconds, so it is not recommended to do so, it is best to get a server of your own.

4, when the user clicked on an IAP item, we first check whether the user allows in-app billing, if not allowed to do the following steps. The code is as follows:

    1. if ([Skpaymentqueue canmakepayments]) {
    2. //Perform the 5th step mentioned below:
    3. [Self getproductinfo];
    4. } Else {
    5. NSLog (@"failed, user prohibited in-app pay purchase.");
    6. }

5, we first through the IAP ProductID to AppStore query, get skpayment instance, and then through the Skpaymentqueue Addpayment method to initiate a purchase operation.

  1. The following ProductID should be a pre-existing paid item added in Itunesconnect. Otherwise, the query will fail.
  2. -(void) Getproductinfo {
  3. Nsset * set = [Nsset setwitharray:@[@"ProductId"]];
  4. Skproductsrequest * request = [[Skproductsrequest alloc] initwithproductidentifiers:set];
  5. Request.delegate = self;
  6. [Request start];
  7. }
  8. callback function for the above query
  9. -(void) Productsrequest: (skproductsrequest *) Request Didreceiveresponse: (Skproductsresponse *) Response {
  10. Nsarray *myproduct = response.products;
  11. if (Myproduct.count = = 0) {
  12. NSLog (@"Unable to get product information, purchase failed. "); 
  13. return;
  14. }
  15. Skpayment * payment = [skpayment paymentwithproduct:myproduct[0]];
  16. [[Skpaymentqueue Defaultqueue] addpayment:payment];
  17. }

6, in the Viewdidload method, the purchase page is set to purchase the observer.

    1. -(void) Viewdidload {
    2. [Super Viewdidload];
    3. //Monitor purchase results
    4. [[Skpaymentqueue Defaultqueue] addtransactionobserver:self];
    5. }
    6. -(void) Viewdidunload {
    7. [Super Viewdidunload];
    8. [[Skpaymentqueue Defaultqueue] removetransactionobserver:self];
    9. }

7, when the user buys the operation has the result, will trigger the following callback function, the corresponding processing can.

  1. -(void) Paymentqueue: (Skpaymentqueue *) queue updatedtransactions: (Nsarray *) Transactions {
  2. For (skpaymenttransaction *transaction in Transactions)
  3. {
  4. switch (transaction.transactionstate)
  5. {
  6. Case skpaymenttransactionstatepurchased://transaction complete
  7. NSLog (@"transactionidentifier =%@", transaction.transactionidentifier);
  8. [Self completetransaction:transaction];
  9. Break ;
  10. Case skpaymenttransactionstatefailed://transaction failed
  11. [Self failedtransaction:transaction];
  12. Break ;
  13. Case skpaymenttransactionstaterestored://has already purchased this product
  14. [Self restoretransaction:transaction];
  15. Break ;
  16. Case skpaymenttransactionstatepurchasing: //Item added into List
  17. NSLog (@"product add to List");
  18. Break ;
  19. Default:
  20. Break ;
  21. }
  22. }
  23. }
  24. -(void) Completetransaction: (skpaymenttransaction *) Transaction {
  25. //Your application should implement these and methods.
  26. NSString * Productidentifier = transaction.payment.productIdentifier;
  27. NSString * receipt = [Transaction.transactionreceipt base64encodedstring];
  28. if ([productidentifier length] > 0) {
  29. //Verify the proof of purchase to your own server
  30. }
  31. //Remove The transaction from the payment queue.
  32. [[Skpaymentqueue Defaultqueue] finishtransaction:transaction];
  33. }
  34. -(void) Failedtransaction: (skpaymenttransaction *) Transaction {
  35. if (transaction.error.code! = skerrorpaymentcancelled) {
  36. NSLog (@"purchase Failed");
  37. } Else {
  38. NSLog (@"user cancels the transaction");
  39. }
  40. [[Skpaymentqueue Defaultqueue] finishtransaction:transaction];
  41. }
  42. -(void) Restoretransaction: (skpaymenttransaction *) Transaction {
  43. //For purchased goods, processing the logic to restore purchases
  44. [[Skpaymentqueue Defaultqueue] finishtransaction:transaction];
  45. }

8, Server Authentication certificate (Optional). If the purchase is successful, we need to send the voucher to the server for verification. Taking into account the network anomalies, the IOS send credential operation should be persisted, if the program exits, crashes or network exceptions, you can resume the retry.

Ii. Development work (service side)

The service side of the work is relatively simple, divided into 4 steps:

    1. Receive proof of purchase from the iOS side.
    2. Determine if the credential already exists or has been validated, and then store the voucher.
    3. Send the credential to Apple's server for authentication and return the validation results to the client.
    4. If necessary, modify the user's corresponding member permissions.

Given the network anomalies, the server's authentication should be a recoverable queue and should be retried if the network fails.

The authentication interface document with Apple is here. In a nutshell, the purchase voucher is encoded with Base64 and then post to the Apple authentication server, and Apple returns the validation results in JSON form.

The verification address for the purchase voucher on the Apple AppStore line is https://buy.itunes.apple.com/verifyReceipt, and the verified address for the test is: https://sandbox.itunes.apple.com/verifyReceipt

[Transfer to]ios in-app payment (IAP) Development steps

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.