diff --git a/src/providers/SubscriptionProvider/SubscriptionProvider.container.js b/src/providers/SubscriptionProvider/SubscriptionProvider.container.js index ef9c1ba0c..7bded8b6d 100644 --- a/src/providers/SubscriptionProvider/SubscriptionProvider.container.js +++ b/src/providers/SubscriptionProvider/SubscriptionProvider.container.js @@ -67,9 +67,12 @@ export class SubscriptionProvider extends Component { }; configPurchaseValidator = () => { + const transformReceipt = this.transformReceipt; + window.CdvPurchase.store.validator = async function(receipt, callback) { try { - const transaction = receipt.transactions[0]; + const transaction = transformReceipt(receipt); + const res = await API.postTransaction(transaction); if (!res.ok) throw res; callback({ @@ -129,6 +132,48 @@ export class SubscriptionProvider extends Component { .finished(receipt => {}); }; + transformReceipt = receipt => { + const receiptTransaction = receipt.transaction; + const receiptData = JSON.parse(receipt.transaction.receipt); + const { + packageName, + productId, + purchaseTime, + purchaseState, + purchaseToken, + quantity, + autoRenewing, + acknowledged + } = receiptData; + const transaction = { + className: 'Transaction', + transactionId: receiptTransaction.id, + state: 'approved', + products: receipt.products, + platform: receiptTransaction.type, + nativePurchase: { + orderId: receiptTransaction.id, + packageName: packageName, + productId: productId, + purchaseTime: purchaseTime, + purchaseState: purchaseState, + purchaseToken: purchaseToken, + quantity: quantity, + autoRenewing: autoRenewing, + acknowledged: acknowledged, + productIds: receipt.products.map(product => product.id), + signature: receiptTransaction.signature, + receipt: receiptTransaction.receipt + }, + purchaseId: purchaseToken, + purchaseDate: new Date(purchaseTime), + isPending: false, + isAcknowledged: acknowledged, + renewalIntent: 'Renew' + }; + return transaction; + }; + render() { const { children } = this.props;