Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

method to retrieve pending transactions #663

Merged
merged 6 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ _*deprecated_<br>~~`buySubscription(sku: string)`~~<ul><li>sku: subscription ID/
`clearTransactionIOS()` | `void` | **iOS only**<br>Clear up the unfinished transanction which sometimes causes problem.<br>Read more in below README.
`clearProductsIOS()` | `void` | **iOS only**<br>Clear all products and subscriptions.<br>Read more in below README.
`requestReceiptIOS()` | `Promise<string>` | **iOS only**<br>Get the current receipt.
`requestPendingPurchasesIOS()` | `Promise<ProductPurchase[]>` | **IOS only**<br>Gets all the transactions which are pending to be finished.
`validateReceiptIos(body: Object, devMode: boolean)`<ul><li>body: receiptBody</li><li>devMode: isTest</li></ul> | `Object\|boolean` | **iOS only**<br>Validate receipt.
`endConnectionAndroid()` | `Promise<void>` | **Android only**<br>End billing connection.
`consumeAllItemsAndroid()` | `Promise<void>` | **Android only**<br>Consume all items so they are able to buy again.
Expand All @@ -126,6 +127,7 @@ _*deprecated_<br>~~`buySubscription(sku: string, prevSku?: string, mode?: number
`requestSubscription(sku: string, prevSku?: string, mode?: number)`<ul><li>sku: subscription ID/sku</li><li>prevSku: old subscription ID/sku (optional)</li><li>mode: proration mode (optional)</li></ul> | `Promise<string>` | **Android only**<br>Create (buy) a subscription to a sku.<br>For upgrading/downgrading subscription on Android pass the second parameter with current subscription ID, on iOS this is handled automatically by store.<br>You can also optionally pass in a proration mode integer for upgrading/downgrading subscriptions on Android
`validateReceiptAndroid(bundleId: string, productId: string, productToken: string, accessToken: string)`<br><ul><li>bundleId: the packageName</li><li>productId: productId</li><li>productToken: productToken</li><li>accessToken: accessToken</li><li>isSubscription: isSubscription</li></ul> | `Object\|boolean` | **Android only**<br>Validate receipt.


</details>

Npm Module
Expand Down
7 changes: 7 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,10 @@ export function purchaseErrorListener(fn: Function) : EmitterSubscription;
* @returns {Promise<string>}
*/
export function requestReceiptIOS(): Promise<string>;

/**
* Request all the pending transactions (IOS only)
* @returns {Promise<ProductPurchase[]>}
*/
export function getPendingPurchasesIOS(): Promise<ProductPurchase[]>;

12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,17 @@ export const requestReceiptIOS = () => {
}
};

/**
* Get the pending purchases in IOS.
* @returns {Promise<ProductPurchase[]>}
*/
export const getPendingPurchasesIOS = () => {
if (Platform.OS === 'ios') {
checkNativeiOSAvailable();
return RNIapIos.getPendingTransactions();
}
};

/**
* deprecated codes
*/
Expand Down Expand Up @@ -521,6 +532,7 @@ export default {
getSubscriptions,
getPurchaseHistory,
getAvailablePurchases,
getPendingPurchasesIOS,
consumeAllItemsAndroid,
buySubscription,
buyProduct,
Expand Down
26 changes: 26 additions & 0 deletions ios/RNIapIos.m
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,32 @@ - (BOOL)shouldAddStorePayment:(SKPayment *)payment forProduct:(SKProduct *)produ
[self finishTransactionWithIdentifier:transactionIdentifier];
}

RCT_EXPORT_METHOD(getPendingTransactions:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
[self requestReceiptDataWithBlock:^(NSData *receiptData, NSError *error) {
if (receiptData == nil) {
resolve(nil);
}
else {
NSArray<SKPaymentTransaction *> *transactions = [[SKPaymentQueue defaultQueue] transactions];
NSMutableArray *output = [NSMutableArray array];

for (SKPaymentTransaction *item in transactions) {
NSMutableDictionary *purchase = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@(item.transactionDate.timeIntervalSince1970 * 1000), @"transactionDate",
item.transactionIdentifier, @"transactionId",
item.payment.productIdentifier, @"productId",
[receiptData base64EncodedStringWithOptions:0], @"transactionReceipt",
nil
];
[output addObject:purchase];
}

resolve(output);
}
}];
}

#pragma mark ===== StoreKit Delegate

-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
Expand Down