Is it enough for WeChat and Alipay to pay for it? Why do we have to pay another apple? Which boss can stand the superfluous thing and apple pays 30% of the money?
Is the boss willing to pay for apple? No, Apple's IOS market is too mandatory. If there are virtual goods transactions in the app, they all need to be paid by apple, otherwise they will be rejected for approval. So, if you want to launch the Apple app store, if you reject the information and ask you to do it,
To a large extent, it just has to be done.
Apple pay, I use App plus payment api , the call is relatively simple. You can learn about it plus payment document
There are two points to understand before using
1. Login iTunes Connet In the application background, create an App internal purchase project and set up the configuration information such as tax and bank card. The specific operation is basically divided into three steps, which can be referred to https://help.apple.com/app-store-connect/#/devb57be10e7
2. HbuilderX needs to mark the custom debugging base. Before marking the test package, remember to check Apple in app payment
Call method used in app
1. First, it must be retrieved plus.payment.getChannels Get the payment channel and get the channel with id 'appleiap'. I'll assign it to the iap variable here. The payment methods are all in this iap
2. Call iap requestOrder Method to request the apple server to obtain the detailed information of goods, that is, the list of internal purchase items. This method must be called to obtain the order information before payment, or the payment fails
3. This step starts to withdraw payment. The api payment of plus, plus.payment.request(channel, statement, successCB, errorCB) Method to initiate a payment request,
Parameters:
- channel: ( PaymentChannel )Required payment channel
Specify the channel of the payment operation, which is obtained through the getChannels interface.
- statement:
(
String
|
JSON
|
OrderStatementIAP
)
Required payment order information
Payment order information, the data format defined by the payment channel, is usually generated by the business server or obtained from the payment server. It is encrypted string information.
- successCB:
(
PaymentSuccessCallback
|
IapPaymentSuccessCallback
)
Optional callback function for successful payment request
Triggered when the payment request is successful. It is used to return the payment result.
- errorCB:
(
PaymentErrorCallback
)
Optional payment request failure callback function
Triggered when the payment request fails. It is used to return error information.
uniapp instance
//First injection iap,For Apple payment var iap = null; plus.payment.getChannels(function(channels) { console.log(channels,"why"); for (var i in channels) { var channel = channels[i]; // obtain id by 'appleiap' of channel if (channel.id === 'appleiap') { iap = channel; } } }, function(e) { console.log("obtain iap Payment channel failed:" + e.message); }); function restoreComplateRequest() { iap.restoreComplateRequest({}, function(results) { // results The format is array to store the recovered data IAP Commodity transaction information object IAPTransaction,The returned payment voucher needs to be sent to the back end for secondary authentication }); } import qs from 'qs'; export default{ data() { return { vi: '' } },
onShow(){
if(this.restoreFlag){
restoreComplateRequest();
}
}, methods:{ payfn(){ if(!iap){return false;} this.onefn(); }, onefn(){ // ids It is the identification collection of in app purchase items configured in the background of Apple developers var ids = ['my25']; // iap For just acquired`appleiap`Payment channel iap.requestOrder(ids, (e)=> { // Successful callback method for obtaining order information console.log('requestOrder success: ' + JSON.stringify(e)); this.twofn(); }, function(e) { // Failed to get order information callback method console.log('requestOrder failed: ' + JSON.stringify(e)); }); }, twofn(){ this.restoreFlag = true; // Mark when calling the payment interface restoreFlag = true , For practical application, please store the tag in storage in plus.payment.request(iap, { productid: "my25", // User ID optimize: true // set up optimize: true Solve the problem of losing orders }, (result)=> {
this.restoreFlag = false; // Payment successfully cleared mark restoreFlag = false // Successful payment, result by IAP Commodity transaction information object IAPTransaction The returned payment voucher needs to be sent to the back end for secondary authentication }, function(e) { console.log(e,"error"); // It needs to be called when the payment fails restoreComplateRequest method restoreComplateRequest() }); } } }
matters needing attention
- When using sandbox environment to test, each time you call the payment interface, you need to change a new test account or commodity. If the same account purchases the same commodity for many times, there may be no callback;
- productid is the product ID of the internal purchase item (user-defined name, which can be obtained as convenient as development)