What are the primary datas?
- User Primay Key
- Subscription Primary Key
There are two major API to handle on the server-side.
CASE: First subscription
You must record user PK with Subscription Key like,
payment: {
userId: '0x39ab948',
originalTransactionId: '2000000159661766',
... purchase detail ...
}
const payment = {
a: 1,
b: 2
}
At this point of view, First you verfiy token got from app store.
Store gives you Base64-encoded data receipt (native-side).
1. Verify Token
docs
https://developer.apple.com/documentation/appstorereceipts/verifyreceipt
Request URL
-Prod
POST https://buy.itunes.apple.com/verifyReceipt
-Sandbox
POST https://sandbox.itunes.apple.com/verifyReceipt
If you use nodeJS frontend server (Koa). you can get post request from native-device
const { user } = ctx.state;
const { receipt } = ctx.request.body;
const appleData = {
'receipt-data': receipt,
password: '#APPLE SECRET KEY#',
'exclude-old-transactions': true, // optional
};
response = axios.post(
"https:buy.itunes.apple.com/verifyRecipt",
appleData
)
If you get response.data.status === 21007, It means that you are in sandbox env.
and then, you get response from app store API.
first you check status === 0 (valid)
using latest_recipt_info and peding_renewal_info
use need to record purchase data
original_transaction_id is primary key of payment.
payment status changes (renew, cancel ...) you find and update payment record by original_transaction_id.
and transaction_id current status ID.
If subscribe
Response Sample
receipt: {
receipt_type: 'ProductionSandbox',
adam_id: 0,
app_item_id: 0,
bundle_id: 'com.###.###',
application_version: '2',
download_id: 0,
version_external_identifier: 0,
receipt_creation_date: '2022-09-21 07:38:22 Etc/GMT',
receipt_creation_date_ms: '1663745902000',
receipt_creation_date_pst: '2022-09-21 00:38:22 America/Los_Angeles',
request_date: '2022-09-21 07:39:02 Etc/GMT',
request_date_ms: '1663745942457',
request_date_pst: '2022-09-21 00:39:02 America/Los_Angeles',
original_purchase_date: '2013-08-01 07:00:00 Etc/GMT',
original_purchase_date_ms: '1375340400000',
original_purchase_date_pst: '2013-08-01 00:00:00 America/Los_Angeles',
original_application_version: '1.0',
in_app: [ [Object], [Object] ]
},
latest_receipt_info: [
{
quantity: '1',
product_id: '###.sub.1m',
transaction_id: '2000000159663851',
original_transaction_id: '2000000159661766',
purchase_date: '2022-09-21 07:36:11 Etc/GMT',
purchase_date_ms: '1663745771000',
purchase_date_pst: '2022-09-21 00:36:11 America/Los_Angeles',
original_purchase_date: '2022-09-21 07:33:12 Etc/GMT',
original_purchase_date_ms: '1663745592000',
original_purchase_date_pst: '2022-09-21 00:33:12 America/Los_Angeles',
expires_date: '2022-09-21 07:39:11 Etc/GMT',
expires_date_ms: '1663745951000',
expires_date_pst: '2022-09-21 00:39:11 America/Los_Angeles',
web_order_line_item_id: '2000000011397885',
is_trial_period: 'false',
is_in_intro_offer_period: 'false',
in_app_ownership_type: 'PURCHASED',
subscription_group_identifier: '21018475'
},
... ,
],
pending_renewal_info: [
{
auto_renew_product_id: '1month',
product_id: '###.sub.1m',
original_transaction_id: '0123456789012345,
auto_renew_status: '1'
}
],
status: 0
'CODE > Javascript' 카테고리의 다른 글
Appstore Server API (0) | 2023.01.31 |
---|---|
How to handle Google Play Subscription (0) | 2023.01.20 |