From 7317113c405bd9b287fcc94dafb0d9ed5264a3f7 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 6 Nov 2023 19:30:23 -0300 Subject: [PATCH 1/4] Transform receipt on purchase validator --- .../SubscriptionProvider.container.js | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) 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; From 5309fb470c799e5a841ca197a1b32c459b4f6fb2 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Tue, 14 Nov 2023 19:53:15 -0300 Subject: [PATCH 2/4] Move transformReceipt() to validator scope --- .../SubscriptionProvider.container.js | 84 +++++++++---------- 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/src/providers/SubscriptionProvider/SubscriptionProvider.container.js b/src/providers/SubscriptionProvider/SubscriptionProvider.container.js index 7bded8b6d..14e846b37 100644 --- a/src/providers/SubscriptionProvider/SubscriptionProvider.container.js +++ b/src/providers/SubscriptionProvider/SubscriptionProvider.container.js @@ -67,7 +67,47 @@ export class SubscriptionProvider extends Component { }; configPurchaseValidator = () => { - const transformReceipt = this.transformReceipt; + const 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; + }; window.CdvPurchase.store.validator = async function(receipt, callback) { try { @@ -132,48 +172,6 @@ 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; From ac9dfb9cb08984014dd02af7ea43a91527c49bca Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Tue, 14 Nov 2023 19:54:04 -0300 Subject: [PATCH 3/4] transformReceipt() just on Android devices --- .../SubscriptionProvider/SubscriptionProvider.container.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/providers/SubscriptionProvider/SubscriptionProvider.container.js b/src/providers/SubscriptionProvider/SubscriptionProvider.container.js index 14e846b37..d6277a13e 100644 --- a/src/providers/SubscriptionProvider/SubscriptionProvider.container.js +++ b/src/providers/SubscriptionProvider/SubscriptionProvider.container.js @@ -111,7 +111,9 @@ export class SubscriptionProvider extends Component { window.CdvPurchase.store.validator = async function(receipt, callback) { try { - const transaction = transformReceipt(receipt); + const transaction = isAndroid() + ? transformReceipt(receipt) + : receipt.transactions[0]; const res = await API.postTransaction(transaction); if (!res.ok) throw res; From 75bd80041a0a27d6d0b6c99ba3ac2999a83362f3 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Thu, 16 Nov 2023 16:57:42 -0300 Subject: [PATCH 4/4] Changes to support isIOS --- .../SubscriptionProvider.container.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/providers/SubscriptionProvider/SubscriptionProvider.container.js b/src/providers/SubscriptionProvider/SubscriptionProvider.container.js index d6277a13e..a2c8f09d8 100644 --- a/src/providers/SubscriptionProvider/SubscriptionProvider.container.js +++ b/src/providers/SubscriptionProvider/SubscriptionProvider.container.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import API from '../../api'; -import { isAndroid } from '../../cordova-util'; +import { isAndroid, isIOS } from '../../cordova-util'; import { updateIsInFreeCountry, @@ -41,7 +41,7 @@ export class SubscriptionProvider extends Component { const isInFreeCountry = updateIsInFreeCountry(); const isOnTrialPeriod = updateIsOnTrialPeriod(); await updatePlans(); - if (isAndroid()) this.configInAppPurchasePlugin(); + if (isAndroid() || isIOS()) this.configInAppPurchasePlugin(); if (!isInFreeCountry && !isOnTrialPeriod && !isSubscribed && isLogged) { showPremiumRequired({ showTryPeriodFinishedMessages: true }); } @@ -111,9 +111,9 @@ export class SubscriptionProvider extends Component { window.CdvPurchase.store.validator = async function(receipt, callback) { try { - const transaction = isAndroid() - ? transformReceipt(receipt) - : receipt.transactions[0]; + const transaction = isIOS() + ? receipt.transaction + : transformReceipt(receipt); const res = await API.postTransaction(transaction); if (!res.ok) throw res;