@unchainedshop/plugins 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/delivery/pick-mup.d.ts +1 -0
- package/lib/delivery/pick-mup.js +98 -0
- package/lib/delivery/pick-mup.js.map +1 -0
- package/lib/delivery/post.d.ts +1 -0
- package/lib/delivery/post.js +23 -0
- package/lib/delivery/post.js.map +1 -0
- package/lib/delivery/send-message.d.ts +1 -0
- package/lib/delivery/send-message.js +41 -0
- package/lib/delivery/send-message.js.map +1 -0
- package/lib/delivery/stores.d.ts +1 -0
- package/lib/delivery/stores.js +39 -0
- package/lib/delivery/stores.js.map +1 -0
- package/lib/enrollments/licensed.d.ts +1 -0
- package/lib/enrollments/licensed.js +40 -0
- package/lib/enrollments/licensed.js.map +1 -0
- package/lib/filters/local-search.d.ts +3 -0
- package/lib/filters/local-search.js +84 -0
- package/lib/filters/local-search.js.map +1 -0
- package/lib/filters/strict-equal.d.ts +1 -0
- package/lib/filters/strict-equal.js +25 -0
- package/lib/filters/strict-equal.js.map +1 -0
- package/lib/payment/apple-iap/adapter.d.ts +1 -0
- package/lib/payment/apple-iap/adapter.js +284 -0
- package/lib/payment/apple-iap/adapter.js.map +1 -0
- package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts +7 -0
- package/lib/payment/apple-iap/db/AppleTransactionsCollection.js +5 -0
- package/lib/payment/apple-iap/db/AppleTransactionsCollection.js.map +1 -0
- package/lib/payment/apple-iap/index.d.ts +2 -0
- package/lib/payment/apple-iap/index.js +3 -0
- package/lib/payment/apple-iap/index.js.map +1 -0
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +9 -0
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +18 -0
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +1 -0
- package/lib/payment/bity/adapter.d.ts +1 -0
- package/lib/payment/bity/adapter.js +316 -0
- package/lib/payment/bity/adapter.js.map +1 -0
- package/lib/payment/bity/db/BityCredentialsCollection.d.ts +11 -0
- package/lib/payment/bity/db/BityCredentialsCollection.js +5 -0
- package/lib/payment/bity/db/BityCredentialsCollection.js.map +1 -0
- package/lib/payment/bity/index.d.ts +2 -0
- package/lib/payment/bity/index.js +3 -0
- package/lib/payment/bity/index.js.map +1 -0
- package/lib/payment/bity/module/configureBityModule.d.ts +11 -0
- package/lib/payment/bity/module/configureBityModule.js +33 -0
- package/lib/payment/bity/module/configureBityModule.js.map +1 -0
- package/lib/payment/braintree.d.ts +1 -0
- package/lib/payment/braintree.js +129 -0
- package/lib/payment/braintree.js.map +1 -0
- package/lib/payment/cryptopay.d.ts +1 -0
- package/lib/payment/cryptopay.js +159 -0
- package/lib/payment/cryptopay.js.map +1 -0
- package/lib/payment/datatrans-v2/api/authorize.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/authorize.js +12 -0
- package/lib/payment/datatrans-v2/api/authorize.js.map +1 -0
- package/lib/payment/datatrans-v2/api/authorizeAuthenticated.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/authorizeAuthenticated.js +11 -0
- package/lib/payment/datatrans-v2/api/authorizeAuthenticated.js.map +1 -0
- package/lib/payment/datatrans-v2/api/cancel.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/cancel.js +10 -0
- package/lib/payment/datatrans-v2/api/cancel.js.map +1 -0
- package/lib/payment/datatrans-v2/api/index.d.ts +19 -0
- package/lib/payment/datatrans-v2/api/index.js +24 -0
- package/lib/payment/datatrans-v2/api/index.js.map +1 -0
- package/lib/payment/datatrans-v2/api/init.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/init.js +31 -0
- package/lib/payment/datatrans-v2/api/init.js.map +1 -0
- package/lib/payment/datatrans-v2/api/makeFetcher.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/makeFetcher.js +41 -0
- package/lib/payment/datatrans-v2/api/makeFetcher.js.map +1 -0
- package/lib/payment/datatrans-v2/api/secureFields.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/secureFields.js +14 -0
- package/lib/payment/datatrans-v2/api/secureFields.js.map +1 -0
- package/lib/payment/datatrans-v2/api/settle.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/settle.js +10 -0
- package/lib/payment/datatrans-v2/api/settle.js.map +1 -0
- package/lib/payment/datatrans-v2/api/status.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/status.js +7 -0
- package/lib/payment/datatrans-v2/api/status.js.map +1 -0
- package/lib/payment/datatrans-v2/api/validate.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/validate.js +10 -0
- package/lib/payment/datatrans-v2/api/validate.js.map +1 -0
- package/lib/payment/datatrans-v2/generateSignature.d.ts +10 -0
- package/lib/payment/datatrans-v2/generateSignature.js +19 -0
- package/lib/payment/datatrans-v2/generateSignature.js.map +1 -0
- package/lib/payment/datatrans-v2/getPaths.d.ts +9 -0
- package/lib/payment/datatrans-v2/getPaths.js +9 -0
- package/lib/payment/datatrans-v2/getPaths.js.map +1 -0
- package/lib/payment/datatrans-v2/index.d.ts +1 -0
- package/lib/payment/datatrans-v2/index.js +384 -0
- package/lib/payment/datatrans-v2/index.js.map +1 -0
- package/lib/payment/datatrans-v2/middleware.d.ts +1 -0
- package/lib/payment/datatrans-v2/middleware.js +111 -0
- package/lib/payment/datatrans-v2/middleware.js.map +1 -0
- package/lib/payment/datatrans-v2/parseRegistrationData.d.ts +11 -0
- package/lib/payment/datatrans-v2/parseRegistrationData.js +26 -0
- package/lib/payment/datatrans-v2/parseRegistrationData.js.map +1 -0
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts +7 -0
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js +10 -0
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js.map +1 -0
- package/lib/payment/datatrans-v2/splitProperties.d.ts +8 -0
- package/lib/payment/datatrans-v2/splitProperties.js +58 -0
- package/lib/payment/datatrans-v2/splitProperties.js.map +1 -0
- package/lib/payment/invoice-prepaid.d.ts +1 -0
- package/lib/payment/invoice-prepaid.js +30 -0
- package/lib/payment/invoice-prepaid.js.map +1 -0
- package/lib/payment/invoice.d.ts +1 -0
- package/lib/payment/invoice.js +27 -0
- package/lib/payment/invoice.js.map +1 -0
- package/lib/payment/paypal-checkout.d.ts +1 -0
- package/lib/payment/paypal-checkout.js +82 -0
- package/lib/payment/paypal-checkout.js.map +1 -0
- package/lib/payment/postfinance-checkout/api.d.ts +11 -0
- package/lib/payment/postfinance-checkout/api.js +109 -0
- package/lib/payment/postfinance-checkout/api.js.map +1 -0
- package/lib/payment/postfinance-checkout/index.d.ts +1 -0
- package/lib/payment/postfinance-checkout/index.js +186 -0
- package/lib/payment/postfinance-checkout/index.js.map +1 -0
- package/lib/payment/postfinance-checkout/middleware.d.ts +1 -0
- package/lib/payment/postfinance-checkout/middleware.js +42 -0
- package/lib/payment/postfinance-checkout/middleware.js.map +1 -0
- package/lib/payment/postfinance-checkout/types.d.ts +23 -0
- package/lib/payment/postfinance-checkout/types.js +12 -0
- package/lib/payment/postfinance-checkout/types.js.map +1 -0
- package/lib/payment/postfinance-checkout/utils.d.ts +4 -0
- package/lib/payment/postfinance-checkout/utils.js +20 -0
- package/lib/payment/postfinance-checkout/utils.js.map +1 -0
- package/lib/payment/stripe.d.ts +1 -0
- package/lib/payment/stripe.js +214 -0
- package/lib/payment/stripe.js.map +1 -0
- package/lib/payment/worldline-saferpay/index.d.ts +1 -0
- package/lib/payment/worldline-saferpay/index.js +112 -0
- package/lib/payment/worldline-saferpay/index.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.d.ts +14 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.js +29 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.d.ts +9 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js +28 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.d.ts +4 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.d.ts +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.d.ts +73 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.d.ts +53 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.d.ts +13 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.d.ts +9 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.d.ts +5 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.d.ts +13 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.js.map +1 -0
- package/lib/pricing/delivery-swiss-tax.d.ts +15 -0
- package/lib/pricing/delivery-swiss-tax.js +98 -0
- package/lib/pricing/delivery-swiss-tax.js.map +1 -0
- package/lib/pricing/discount-100-off.d.ts +1 -0
- package/lib/pricing/discount-100-off.js +34 -0
- package/lib/pricing/discount-100-off.js.map +1 -0
- package/lib/pricing/discount-half-price-manual.d.ts +1 -0
- package/lib/pricing/discount-half-price-manual.js +34 -0
- package/lib/pricing/discount-half-price-manual.js.map +1 -0
- package/lib/pricing/discount-half-price.d.ts +1 -0
- package/lib/pricing/discount-half-price.js +37 -0
- package/lib/pricing/discount-half-price.js.map +1 -0
- package/lib/pricing/free-delivery.d.ts +2 -0
- package/lib/pricing/free-delivery.js +26 -0
- package/lib/pricing/free-delivery.js.map +1 -0
- package/lib/pricing/free-payment.d.ts +2 -0
- package/lib/pricing/free-payment.js +26 -0
- package/lib/pricing/free-payment.js.map +1 -0
- package/lib/pricing/order-delivery.d.ts +1 -0
- package/lib/pricing/order-delivery.js +33 -0
- package/lib/pricing/order-delivery.js.map +1 -0
- package/lib/pricing/order-discount.d.ts +1 -0
- package/lib/pricing/order-discount.js +110 -0
- package/lib/pricing/order-discount.js.map +1 -0
- package/lib/pricing/order-items-discount.d.ts +1 -0
- package/lib/pricing/order-items-discount.js +88 -0
- package/lib/pricing/order-items-discount.js.map +1 -0
- package/lib/pricing/order-items.d.ts +1 -0
- package/lib/pricing/order-items.js +44 -0
- package/lib/pricing/order-items.js.map +1 -0
- package/lib/pricing/order-payment.d.ts +1 -0
- package/lib/pricing/order-payment.js +33 -0
- package/lib/pricing/order-payment.js.map +1 -0
- package/lib/pricing/product-catalog-price.d.ts +1 -0
- package/lib/pricing/product-catalog-price.js +37 -0
- package/lib/pricing/product-catalog-price.js.map +1 -0
- package/lib/pricing/product-discount.d.ts +1 -0
- package/lib/pricing/product-discount.js +55 -0
- package/lib/pricing/product-discount.js.map +1 -0
- package/lib/pricing/product-price-ECB-interbank-exchange.d.ts +1 -0
- package/lib/pricing/product-price-ECB-interbank-exchange.js +90 -0
- package/lib/pricing/product-price-ECB-interbank-exchange.js.map +1 -0
- package/lib/pricing/product-price-coinbase-exchange.d.ts +1 -0
- package/lib/pricing/product-price-coinbase-exchange.js +60 -0
- package/lib/pricing/product-price-coinbase-exchange.js.map +1 -0
- package/lib/pricing/product-price-cryptopay.d.ts +1 -0
- package/lib/pricing/product-price-cryptopay.js +21 -0
- package/lib/pricing/product-price-cryptopay.js.map +1 -0
- package/lib/pricing/product-price-rateconversion.d.ts +1 -0
- package/lib/pricing/product-price-rateconversion.js +51 -0
- package/lib/pricing/product-price-rateconversion.js.map +1 -0
- package/lib/pricing/product-price-round.d.ts +11 -0
- package/lib/pricing/product-price-round.js +54 -0
- package/lib/pricing/product-price-round.js.map +1 -0
- package/lib/pricing/product-swiss-tax.d.ts +13 -0
- package/lib/pricing/product-swiss-tax.js +102 -0
- package/lib/pricing/product-swiss-tax.js.map +1 -0
- package/lib/pricing/utils/cache.d.ts +9 -0
- package/lib/pricing/utils/cache.js +28 -0
- package/lib/pricing/utils/cache.js.map +1 -0
- package/lib/quotations/manual.d.ts +1 -0
- package/lib/quotations/manual.js +21 -0
- package/lib/quotations/manual.js.map +1 -0
- package/lib/warehousing/google-sheets.d.ts +1 -0
- package/lib/warehousing/google-sheets.js +153 -0
- package/lib/warehousing/google-sheets.js.map +1 -0
- package/lib/warehousing/store.d.ts +1 -0
- package/lib/warehousing/store.js +33 -0
- package/lib/warehousing/store.js.map +1 -0
- package/lib/worker/BulkImportWorker.js +3 -3
- package/lib/worker/BulkImportWorker.js.map +1 -1
- package/lib/worker/GenerateOrderWorker.js +1 -1
- package/lib/worker/GenerateOrderWorker.js.map +1 -1
- package/lib/worker/email.js +55 -4
- package/lib/worker/email.js.map +1 -1
- package/package.json +18 -2
- package/src/delivery/pick-mup.ts +119 -0
- package/src/delivery/post.ts +30 -0
- package/src/delivery/send-message.ts +54 -0
- package/src/delivery/stores.ts +49 -0
- package/src/enrollments/licensed.ts +49 -0
- package/src/filters/local-search.ts +105 -0
- package/src/filters/strict-equal.ts +31 -0
- package/src/payment/apple-iap/adapter.ts +390 -0
- package/src/payment/apple-iap/db/AppleTransactionsCollection.ts +13 -0
- package/src/payment/apple-iap/index.ts +3 -0
- package/src/payment/apple-iap/module/configureAppleTransactionsModule.ts +31 -0
- package/src/payment/bity/adapter.ts +417 -0
- package/src/payment/bity/db/BityCredentialsCollection.ts +17 -0
- package/src/payment/bity/index.ts +3 -0
- package/src/payment/bity/module/configureBityModule.ts +46 -0
- package/src/payment/braintree.ts +147 -0
- package/src/payment/cryptopay.ts +195 -0
- package/src/payment/datatrans-v2/api/authorize.ts +17 -0
- package/src/payment/datatrans-v2/api/authorizeAuthenticated.ts +20 -0
- package/src/payment/datatrans-v2/api/cancel.ts +13 -0
- package/src/payment/datatrans-v2/api/index.ts +24 -0
- package/src/payment/datatrans-v2/api/init.ts +40 -0
- package/src/payment/datatrans-v2/api/makeFetcher.ts +49 -0
- package/src/payment/datatrans-v2/api/secureFields.ts +19 -0
- package/src/payment/datatrans-v2/api/settle.ts +13 -0
- package/src/payment/datatrans-v2/api/status.ts +8 -0
- package/src/payment/datatrans-v2/api/types.d.ts +378 -0
- package/src/payment/datatrans-v2/api/validate.ts +13 -0
- package/src/payment/datatrans-v2/generateSignature.ts +24 -0
- package/src/payment/datatrans-v2/getPaths.ts +24 -0
- package/src/payment/datatrans-v2/index.ts +476 -0
- package/src/payment/datatrans-v2/middleware.ts +147 -0
- package/src/payment/datatrans-v2/parseRegistrationData.ts +32 -0
- package/src/payment/datatrans-v2/roundedAmountFromOrder.ts +16 -0
- package/src/payment/datatrans-v2/splitProperties.ts +63 -0
- package/src/payment/invoice-prepaid.ts +40 -0
- package/src/payment/invoice.ts +36 -0
- package/src/payment/paypal-checkout.ts +107 -0
- package/src/payment/postfinance-checkout/api.ts +142 -0
- package/src/payment/postfinance-checkout/index.ts +241 -0
- package/src/payment/postfinance-checkout/middleware.ts +54 -0
- package/src/payment/postfinance-checkout/types.ts +27 -0
- package/src/payment/postfinance-checkout/utils.ts +35 -0
- package/src/payment/stripe.ts +278 -0
- package/src/payment/worldline-saferpay/index.ts +140 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.ts +54 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.ts +36 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/index.ts +8 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.ts +26 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.ts +75 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.ts +55 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/Request.ts +14 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/Response.ts +9 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.ts +6 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.ts +15 -0
- package/src/pricing/delivery-swiss-tax.ts +115 -0
- package/src/pricing/discount-100-off.ts +44 -0
- package/src/pricing/discount-half-price-manual.ts +43 -0
- package/src/pricing/discount-half-price.ts +46 -0
- package/src/pricing/free-delivery.ts +31 -0
- package/src/pricing/free-payment.ts +32 -0
- package/src/pricing/order-delivery.ts +45 -0
- package/src/pricing/order-discount.ts +158 -0
- package/src/pricing/order-items-discount.ts +116 -0
- package/src/pricing/order-items.ts +61 -0
- package/src/pricing/order-payment.ts +46 -0
- package/src/pricing/product-catalog-price.ts +56 -0
- package/src/pricing/product-discount.ts +69 -0
- package/src/pricing/product-price-ECB-interbank-exchange.ts +108 -0
- package/src/pricing/product-price-coinbase-exchange.ts +82 -0
- package/src/pricing/product-price-cryptopay.ts +25 -0
- package/src/pricing/product-price-rateconversion.ts +73 -0
- package/src/pricing/product-price-round.ts +78 -0
- package/src/pricing/product-swiss-tax.ts +117 -0
- package/src/pricing/utils/cache.js +32 -0
- package/src/quotations/manual.ts +27 -0
- package/src/warehousing/google-sheets.ts +165 -0
- package/src/warehousing/store.ts +47 -0
- package/src/worker/BulkImportWorker.ts +3 -3
- package/src/worker/GenerateOrderWorker.ts +1 -1
- package/src/worker/email.ts +56 -4
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import { Context } from '@unchainedshop/types/api';
|
|
2
|
+
import { IPaymentAdapter } from '@unchainedshop/types/payments';
|
|
3
|
+
import bodyParser from 'body-parser';
|
|
4
|
+
import fetch from 'isomorphic-unfetch';
|
|
5
|
+
import { useMiddlewareWithCurrentContext } from 'meteor/unchained:api';
|
|
6
|
+
import { EnrollmentStatus } from '@unchainedshop/core-enrollments';
|
|
7
|
+
import { PaymentAdapter, PaymentDirector, PaymentError } from '@unchainedshop/core-payment';
|
|
8
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
9
|
+
import { AppleTransactionsModule } from './module/configureAppleTransactionsModule';
|
|
10
|
+
|
|
11
|
+
const logger = createLogger('unchained:core-payment:iap');
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
APPLE_IAP_SHARED_SECRET,
|
|
15
|
+
APPLE_IAP_ENVIRONMENT = 'sandbox',
|
|
16
|
+
APPLE_IAP_WEBHOOK_PATH = '/graphql/apple-iap',
|
|
17
|
+
} = process.env;
|
|
18
|
+
|
|
19
|
+
// https://developer.apple.com/documentation/storekit/in-app_purchase/validating_receipts_with_the_app_store
|
|
20
|
+
const environments = {
|
|
21
|
+
sandbox: 'https://sandbox.itunes.apple.com/verifyReceipt',
|
|
22
|
+
production: 'https://buy.itunes.apple.com/verifyReceipt',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const verifyReceipt = async ({ receiptData, password }) => {
|
|
26
|
+
const payload: any = {
|
|
27
|
+
'receipt-data': receiptData,
|
|
28
|
+
};
|
|
29
|
+
if (password) {
|
|
30
|
+
payload.password = password;
|
|
31
|
+
}
|
|
32
|
+
const result = await fetch(environments[APPLE_IAP_ENVIRONMENT], {
|
|
33
|
+
body: JSON.stringify(payload),
|
|
34
|
+
method: 'POST',
|
|
35
|
+
headers: {
|
|
36
|
+
'Content-Type': 'application/json',
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
return result.json();
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const AppleNotificationTypes = {
|
|
43
|
+
INITIAL_BUY: 'INITIAL_BUY',
|
|
44
|
+
DID_RECOVER: 'DID_RECOVER',
|
|
45
|
+
DID_CHANGE_RENEWAL_STATUS: 'DID_CHANGE_RENEWAL_STATUS',
|
|
46
|
+
DID_FAIL_TO_RENEW: 'DID_FAIL_TO_RENEW',
|
|
47
|
+
DID_CHANGE_RENEWAL_PREF: 'DID_CHANGE_RENEWAL_PREF',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const fixPeriods = async (
|
|
51
|
+
{ transactionId, enrollmentId, orderId, transactions },
|
|
52
|
+
requestContext: Context,
|
|
53
|
+
) => {
|
|
54
|
+
const relevantTransactions = transactions.filter(
|
|
55
|
+
// eslint-disable-next-line
|
|
56
|
+
({ original_transaction_id }) => {
|
|
57
|
+
return original_transaction_id === transactionId; // eslint-disable-line
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const adjustedEnrollmentPeriods = relevantTransactions
|
|
62
|
+
.map((transaction) => {
|
|
63
|
+
return {
|
|
64
|
+
isTrial: transaction.is_trial_period === 'true', // eslint-disable-line
|
|
65
|
+
start: new Date(parseInt(transaction.purchase_date_ms, 10)),
|
|
66
|
+
end: new Date(parseInt(transaction.expires_date_ms, 10)),
|
|
67
|
+
orderId: transaction.transaction_id === transactionId ? orderId : null,
|
|
68
|
+
};
|
|
69
|
+
})
|
|
70
|
+
.sort((left, right) => {
|
|
71
|
+
return left.end.getTime() - right.end.getTime();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
await requestContext.modules.enrollments.removeEnrollmentPeriodByOrderId(
|
|
75
|
+
enrollmentId,
|
|
76
|
+
orderId,
|
|
77
|
+
requestContext.userId,
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
return Promise.all(
|
|
81
|
+
adjustedEnrollmentPeriods.map((period) =>
|
|
82
|
+
requestContext.modules.enrollments.addEnrollmentPeriod(
|
|
83
|
+
enrollmentId,
|
|
84
|
+
period,
|
|
85
|
+
requestContext.userId,
|
|
86
|
+
),
|
|
87
|
+
),
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
useMiddlewareWithCurrentContext(
|
|
92
|
+
APPLE_IAP_WEBHOOK_PATH,
|
|
93
|
+
bodyParser.json({
|
|
94
|
+
strict: false,
|
|
95
|
+
}),
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
useMiddlewareWithCurrentContext(APPLE_IAP_WEBHOOK_PATH, async (req, res) => {
|
|
99
|
+
if (req.method === 'POST') {
|
|
100
|
+
try {
|
|
101
|
+
const resolvedContext = req.unchainedContext as Context;
|
|
102
|
+
const { modules, services } = resolvedContext;
|
|
103
|
+
const responseBody = req.body || {};
|
|
104
|
+
if (responseBody.password !== APPLE_IAP_SHARED_SECRET) {
|
|
105
|
+
throw new Error('shared secret not valid');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const transactions = responseBody?.unified_receipt?.latest_receipt_info; // eslint-disable-line
|
|
109
|
+
const latestTransaction = transactions[0];
|
|
110
|
+
|
|
111
|
+
if (responseBody.notification_type === AppleNotificationTypes.INITIAL_BUY) {
|
|
112
|
+
// Find the cart to checkout
|
|
113
|
+
const orderPayment = await modules.orders.payments.findOrderPaymentByContextData({
|
|
114
|
+
context: {
|
|
115
|
+
'meta.transactionIdentifier': latestTransaction.transaction_id,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
if (!orderPayment) throw new Error('Could not find any matching order payment');
|
|
120
|
+
const order = await modules.orders.findOrder({
|
|
121
|
+
orderId: orderPayment.orderId,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
if (modules.orders.isCart(order)) {
|
|
125
|
+
// checkout if is cart, else just ignore because the cart is already checked out
|
|
126
|
+
// through submission of the receipt with GraphQL
|
|
127
|
+
const checkedOut = await modules.orders.checkout(
|
|
128
|
+
order._id,
|
|
129
|
+
{
|
|
130
|
+
transactionContext: {
|
|
131
|
+
receiptData: responseBody?.unified_receipt?.latest_receipt, // eslint-disable-line
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
resolvedContext,
|
|
135
|
+
);
|
|
136
|
+
const orderId = checkedOut._id;
|
|
137
|
+
const enrollment = await modules.enrollments.findEnrollment({
|
|
138
|
+
orderId,
|
|
139
|
+
});
|
|
140
|
+
await fixPeriods(
|
|
141
|
+
{
|
|
142
|
+
transactionId: latestTransaction.original_transaction_id,
|
|
143
|
+
transactions,
|
|
144
|
+
enrollmentId: enrollment._id,
|
|
145
|
+
orderId,
|
|
146
|
+
},
|
|
147
|
+
resolvedContext,
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
logger.info(`Apple IAP Webhook: Confirmed checkout for order ${checkedOut.orderNumber}`, {
|
|
151
|
+
orderId: checkedOut._id,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
// Just store payment credentials, use the enrollments paymentProvider reference and
|
|
156
|
+
// let the job do the rest
|
|
157
|
+
const originalOrderPayment = await modules.orders.payments.findOrderPaymentByContextData({
|
|
158
|
+
context: {
|
|
159
|
+
'meta.transactionIdentifier': latestTransaction.original_transaction_id,
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
if (!originalOrderPayment) throw new Error('Could not find any matching order payment');
|
|
163
|
+
const originalOrder = await modules.orders.findOrder({
|
|
164
|
+
orderId: originalOrderPayment.orderId,
|
|
165
|
+
});
|
|
166
|
+
const enrollment = await modules.enrollments.findEnrollment({
|
|
167
|
+
orderId: originalOrder._id,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
await services.payment.registerPaymentCredentials(
|
|
171
|
+
enrollment.payment.paymentProviderId,
|
|
172
|
+
{
|
|
173
|
+
transactionContext: {
|
|
174
|
+
receiptData: responseBody?.unified_receipt?.latest_receipt, // eslint-disable-line
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
resolvedContext,
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
await fixPeriods(
|
|
181
|
+
{
|
|
182
|
+
transactionId: latestTransaction.original_transaction_id,
|
|
183
|
+
transactions,
|
|
184
|
+
enrollmentId: enrollment._id,
|
|
185
|
+
orderId: originalOrder._id,
|
|
186
|
+
},
|
|
187
|
+
resolvedContext,
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
logger.info(
|
|
191
|
+
`Apple IAP Webhook: Processed notification for ${latestTransaction.original_transaction_id} and type ${responseBody.notification_type}`,
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
if (responseBody.notification_type === AppleNotificationTypes.DID_RECOVER) {
|
|
195
|
+
if (
|
|
196
|
+
enrollment.status !== EnrollmentStatus.TERMINATED &&
|
|
197
|
+
responseBody.auto_renew_status === 'false'
|
|
198
|
+
) {
|
|
199
|
+
await modules.enrollments.terminateEnrollment(enrollment, {}, resolvedContext);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (responseBody.notification_type === AppleNotificationTypes.DID_CHANGE_RENEWAL_STATUS) {
|
|
204
|
+
if (
|
|
205
|
+
enrollment.status !== EnrollmentStatus.TERMINATED &&
|
|
206
|
+
responseBody.auto_renew_status === 'false'
|
|
207
|
+
) {
|
|
208
|
+
await modules.enrollments.terminateEnrollment(enrollment, {}, resolvedContext);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
logger.info(`Apple IAP Webhook: Updated enrollment from Apple`);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
res.writeHead(200);
|
|
215
|
+
res.end();
|
|
216
|
+
return;
|
|
217
|
+
} catch (e) {
|
|
218
|
+
logger.warn(`Apple IAP Webhook: ${e.message}`, e);
|
|
219
|
+
res.writeHead(503);
|
|
220
|
+
res.end(JSON.stringify(e));
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
res.writeHead(404);
|
|
225
|
+
res.end();
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
const AppleIAP: IPaymentAdapter = {
|
|
229
|
+
...PaymentAdapter,
|
|
230
|
+
|
|
231
|
+
key: 'shop.unchained.apple-iap',
|
|
232
|
+
label: 'Apple In-App-Purchase',
|
|
233
|
+
version: '1.0',
|
|
234
|
+
initialConfiguration: [],
|
|
235
|
+
|
|
236
|
+
typeSupported: (type) => {
|
|
237
|
+
return type === 'GENERIC';
|
|
238
|
+
},
|
|
239
|
+
|
|
240
|
+
actions: (params) => {
|
|
241
|
+
const { modules, userId } = params.context;
|
|
242
|
+
|
|
243
|
+
const adapterActions = {
|
|
244
|
+
...PaymentAdapter.actions(params),
|
|
245
|
+
|
|
246
|
+
configurationError() {
|
|
247
|
+
// eslint-disable-line
|
|
248
|
+
if (!APPLE_IAP_SHARED_SECRET) {
|
|
249
|
+
return PaymentError.INCOMPLETE_CONFIGURATION;
|
|
250
|
+
}
|
|
251
|
+
return null;
|
|
252
|
+
},
|
|
253
|
+
|
|
254
|
+
isActive() {
|
|
255
|
+
if (adapterActions.configurationError() === null) return true;
|
|
256
|
+
return false;
|
|
257
|
+
},
|
|
258
|
+
|
|
259
|
+
// eslint-disable-next-line
|
|
260
|
+
isPayLaterAllowed() {
|
|
261
|
+
return false;
|
|
262
|
+
},
|
|
263
|
+
|
|
264
|
+
// eslint-disable-next-line
|
|
265
|
+
async sign() {
|
|
266
|
+
throw new Error('Apple IAP does not support payment signing');
|
|
267
|
+
},
|
|
268
|
+
|
|
269
|
+
// eslint-disable-next-line
|
|
270
|
+
async validate() {
|
|
271
|
+
// once registered receipt transactions are valid by default!
|
|
272
|
+
return true;
|
|
273
|
+
},
|
|
274
|
+
|
|
275
|
+
// eslint-disable-next-line
|
|
276
|
+
async register(transactionContext) {
|
|
277
|
+
const { receiptData } = transactionContext;
|
|
278
|
+
|
|
279
|
+
const response = await verifyReceipt({
|
|
280
|
+
receiptData,
|
|
281
|
+
password: APPLE_IAP_SHARED_SECRET,
|
|
282
|
+
});
|
|
283
|
+
const { status, latest_receipt_info: latestReceiptInfo } = response; // eslint-disable-line
|
|
284
|
+
|
|
285
|
+
if (status === 0) {
|
|
286
|
+
logger.info('Apple IAP Plugin: Receipt validated and updated for the user', {
|
|
287
|
+
level: 'verbose',
|
|
288
|
+
});
|
|
289
|
+
const latestTransaction = latestReceiptInfo[latestReceiptInfo.length - 1]; // eslint-disable-line
|
|
290
|
+
return {
|
|
291
|
+
token: latestTransaction.web_order_line_item_id, // eslint-disable-line
|
|
292
|
+
latestReceiptInfo,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
logger.warn('Apple IAP Plugin: Receipt invalid', {
|
|
297
|
+
level: 'warn',
|
|
298
|
+
status: response.status,
|
|
299
|
+
});
|
|
300
|
+
return null;
|
|
301
|
+
},
|
|
302
|
+
|
|
303
|
+
// eslint-disable-next-line
|
|
304
|
+
async charge(transactionContext) {
|
|
305
|
+
const { order } = params.paymentContext;
|
|
306
|
+
const { meta, paymentCredentials, receiptData } = transactionContext || {};
|
|
307
|
+
const { transactionIdentifier } = meta || {};
|
|
308
|
+
const appleTransactions = (params.context.modules as any)
|
|
309
|
+
.appleTransactions as AppleTransactionsModule;
|
|
310
|
+
|
|
311
|
+
if (!transactionIdentifier) {
|
|
312
|
+
throw new Error('Apple IAP Plugin: You have to set the transaction id on the order payment');
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const receiptResponse =
|
|
316
|
+
receiptData &&
|
|
317
|
+
(await verifyReceipt({
|
|
318
|
+
receiptData,
|
|
319
|
+
password: APPLE_IAP_SHARED_SECRET,
|
|
320
|
+
}));
|
|
321
|
+
|
|
322
|
+
if (receiptResponse && receiptResponse.status !== 0) {
|
|
323
|
+
throw new Error('Apple IAP Plugin: Receipt invalid');
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const transactions =
|
|
327
|
+
receiptResponse?.latest_receipt_info || // eslint-disable-line
|
|
328
|
+
paymentCredentials?.meta?.latestReceiptInfo;
|
|
329
|
+
const matchedTransaction = transactions?.find(
|
|
330
|
+
(transaction) => transaction?.transaction_id === transactionIdentifier, // eslint-disable-line
|
|
331
|
+
);
|
|
332
|
+
if (!matchedTransaction) {
|
|
333
|
+
throw new Error(
|
|
334
|
+
`Apple IAP Plugin: Cannot match transaction with identifier ${transactionIdentifier}`,
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const orderPositions = await modules.orders.positions.findOrderPositions({
|
|
339
|
+
orderId: order._id,
|
|
340
|
+
});
|
|
341
|
+
const items = Object.entries(
|
|
342
|
+
orderPositions.reduce((acc, item) => {
|
|
343
|
+
return {
|
|
344
|
+
...acc,
|
|
345
|
+
[item.productId]: (acc[item.productId] || 0) + item.quantity,
|
|
346
|
+
};
|
|
347
|
+
}, {}),
|
|
348
|
+
);
|
|
349
|
+
|
|
350
|
+
if (items.length !== 1) {
|
|
351
|
+
throw new Error('Apple IAP Plugin: You can only checkout 1 unique product at once');
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const [[productId, quantity]] = items;
|
|
355
|
+
|
|
356
|
+
const isMatchesTransaction =
|
|
357
|
+
parseInt(matchedTransaction.quantity, 10) === quantity &&
|
|
358
|
+
matchedTransaction.product_id === productId; // eslint-disable-line
|
|
359
|
+
|
|
360
|
+
if (!isMatchesTransaction)
|
|
361
|
+
throw new Error('Apple IAP Plugin: Product in order does not match transaction');
|
|
362
|
+
|
|
363
|
+
const alreadyProcessedTransaction = await appleTransactions.findTransactionById(
|
|
364
|
+
transactionIdentifier,
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
if (alreadyProcessedTransaction)
|
|
368
|
+
throw new Error('Apple IAP Plugin: Transaction already processed');
|
|
369
|
+
|
|
370
|
+
// All good
|
|
371
|
+
await appleTransactions.createTransaction(
|
|
372
|
+
{
|
|
373
|
+
_id: transactionIdentifier,
|
|
374
|
+
matchedTransaction,
|
|
375
|
+
orderId: order._id,
|
|
376
|
+
},
|
|
377
|
+
userId,
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
return {
|
|
381
|
+
transactionIdentifier,
|
|
382
|
+
};
|
|
383
|
+
},
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
return adapterActions;
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
PaymentDirector.registerAdapter(AppleIAP);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Db, TimestampFields, _ID } from '@unchainedshop/types/common';
|
|
2
|
+
|
|
3
|
+
export type AppleTransaction = {
|
|
4
|
+
_id?: _ID;
|
|
5
|
+
matchedTransaction: any;
|
|
6
|
+
orderId: string;
|
|
7
|
+
} & TimestampFields;
|
|
8
|
+
|
|
9
|
+
export const AppleTransactionsCollection = async (db: Db) => {
|
|
10
|
+
const AppleTransactions = db.collection<AppleTransaction>('payment_apple_iap_processed_transactions');
|
|
11
|
+
|
|
12
|
+
return AppleTransactions;
|
|
13
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Db } from '@unchainedshop/types/common';
|
|
2
|
+
import { AppleTransaction, AppleTransactionsCollection } from '../db/AppleTransactionsCollection';
|
|
3
|
+
|
|
4
|
+
export interface AppleTransactionsModule {
|
|
5
|
+
findTransactionById: (transactionIdentifier: string) => Promise<AppleTransaction>;
|
|
6
|
+
|
|
7
|
+
createTransaction: (doc: AppleTransaction, userId: string) => Promise<string | null>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const configureAppleTransactionsModule = async ({
|
|
11
|
+
db,
|
|
12
|
+
}: {
|
|
13
|
+
db: Db;
|
|
14
|
+
}): Promise<AppleTransactionsModule> => {
|
|
15
|
+
const AppleTransactions = await AppleTransactionsCollection(db);
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
findTransactionById: async (transactionIdentifier) => {
|
|
19
|
+
return AppleTransactions.findOne({ _id: transactionIdentifier });
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
createTransaction: async (doc, userId) => {
|
|
23
|
+
await AppleTransactions.insertOne({
|
|
24
|
+
...doc,
|
|
25
|
+
created: new Date(),
|
|
26
|
+
createdBy: userId,
|
|
27
|
+
});
|
|
28
|
+
return doc._id;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
};
|