Skip to content

Commit

Permalink
Move transformReceipt() to validator scope
Browse files Browse the repository at this point in the history
  • Loading branch information
RodriSanchez1 committed Nov 14, 2023
1 parent 7317113 commit 5309fb4
Showing 1 changed file with 41 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 5309fb4

Please sign in to comment.