@nativescript/payments
Version:
In-App Purchase and Subscriptions for NativeScript
43 lines • 2 kB
JavaScript
import { BaseOrder, OrderState } from './common';
export { OrderState } from './common';
export class Order extends BaseOrder {
constructor(nativeValue, restored = false) {
super(nativeValue, restored);
switch (nativeValue.transactionState) {
case 1 /* SKPaymentTransactionState.Purchased */:
this.state = OrderState.VALID;
break;
case 4 /* SKPaymentTransactionState.Deferred */:
case 0 /* SKPaymentTransactionState.Purchasing */:
case 3 /* SKPaymentTransactionState.Restored */:
this.state = OrderState.PROVISIONAL;
break;
case 2 /* SKPaymentTransactionState.Failed */:
default:
this.state = OrderState.INVALID;
break;
}
this.itemId = nativeValue.payment ? nativeValue.payment.productIdentifier : 'undefined';
this.orderId = nativeValue.transactionIdentifier;
this.orderDate = nativeValue.transactionDate;
const receiptData = NSData.dataWithContentsOfURL(NSBundle.mainBundle.appStoreReceiptURL);
this.receiptToken = receiptData ? receiptData.base64EncodedStringWithOptions(1 /* NSDataBase64EncodingOptions.Encoding64CharacterLineLength */) : undefined;
// this.receiptToken = nativeValue.transactionReceipt ? nativeValue.transactionReceipt.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength) : 'undefined';
this.userData = nativeValue.payment ? nativeValue.payment.applicationUsername : 'undefined';
}
get debug() {
if (this.nativeValue) {
const temp = {};
for (const i in this.nativeValue) {
if (this.nativeValue[i] != null) {
temp[i] = this.nativeValue[i];
}
}
return JSON.stringify(temp);
}
else {
return null;
}
}
}
//# sourceMappingURL=index.ios.js.map