@salla.sa/twilight-components 2.12.56 → 2.12.58

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.
@@ -65,15 +65,15 @@ export class SallaQuickBuy {
65
65
  supportedCountries: salla.config.get('store.settings.buy_now.countries'),
66
66
  validateMerchant: {
67
67
  url: salla.url.get('checkout/applepay/validate'),
68
- onSuccess: () => {
68
+ onSuccess: (response) => {
69
69
  if (this.applePayOnly && !this.productId) { // the cart is not passes
70
70
  if (!this.cartId) {
71
71
  salla.logger.warn('🍏 Pay: trying to create applePay transaction without cartId/ProductId !');
72
- return;
72
+ return response;
73
73
  }
74
74
  window.SallaApplePay.id = this.cartId;
75
75
  salla.log('🍏 Pay: create checkout success: with id #' + this.cartId);
76
- return;
76
+ return response;
77
77
  }
78
78
  return salla.api.request('checkout/quick-purchase/' + this.productId, typeof data == 'object' ? data : undefined, 'post', {}).then(response => {
79
79
  var _a, _b;
@@ -1 +1 @@
1
- {"version":3,"file":"salla-quick-buy.js","sourceRoot":"","sources":["../../../src/components/salla-quick-buy/salla-quick-buy.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,UAAU,MAAM,kCAAkC,CAAC;AAC1D,OAAO,8BAA8B,CAAC;AAMtC,MAAM,OAAO,aAAa;EACxB;gBAoBuF,KAAK;;;;;mBAsC1E,EAAE;;;;oBAgBQ,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,wBAAwB,CAAC;IAzElE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE;MACvB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;IAEH,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,EA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C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Host, h, Prop, State, Element } from '@stencil/core';\nimport FullWallet from '../../assets/svg/full-wallet.svg';\nimport \"@salla.sa/applepay/src/index\";\n\n@Component({\n tag: 'salla-quick-buy',\n styleUrl: 'salla-quick-buy.scss',\n})\nexport class SallaQuickBuy {\n constructor() {\n salla.lang.onLoaded(() => {\n this.quickBuy = salla.lang.get('pages.products.buy_now');\n });\n\n if (salla.config.isGuest()) {\n let eventName = \"salla-quick-buy::user.logged-in\"\n salla.api.auth.setAfterLoginEvent(eventName)\n salla.event.on(eventName, () => this.settlePayment())\n }\n }\n\n @Element() host: HTMLElement;\n\n /**\n * Button type.\n *\n * @type {string}\n * @default buy\n **/\n @Prop({ mutable: true }) type: 'plain' | 'buy' | 'donate' | 'book' | 'pay' | 'order' = 'buy';\n\n /**\n * Product ID.\n *\n * @type {string}\n **/\n @Prop({ mutable: true }) productId: string;\n\n /**\n * Cart ID, when you need to applePay for existed cart\n *\n * @type {string}\n **/\n @Prop({ mutable: true }) cartId: string;\n\n /**\n * Product amount in base currency (SAR).\n *\n * @type {number}\n * @default 0\n **/\n @Prop({ reflect: true, mutable: true }) amount: number;\n\n /**\n * base currency\n *\n * @type {string}\n * @default SAR\n */\n @Prop({ mutable: true }) currency: string;\n\n /**\n * Product options, if is empty will get the data from the document.querySelector('salla-product-options[product-id=\"X\"]')\n *\n * @type {object}\n * @default {}\n */\n @Prop() options = {};\n\n /**\n * To be passed to purchaseNow request\n * @type {boolean}\n **/\n @Prop({mutable: true}) isRequireShipping: boolean;\n \n /**\n * Show Apple Pay only\n * @type {boolean}\n **/\n @Prop({mutable: true}) applePayOnly: boolean;\n\n @State() isApplePayActive: boolean;\n\n @State() quickBuy: string = salla.lang.get('pages.products.buy_now');\n\n private async quickBuyHandler() {\n if (salla.config.isGuest()) {\n // todo (low) :: find a way to re-fire the method after success\n return salla.auth.event.dispatch('login::open', { withoutReload: true });\n }\n await this.settlePayment()\n }\n\n private async settlePayment() {\n\n let optionsElement = document.querySelector(`salla-product-options[product-id=\"${this.productId}\"]`) as HTMLSallaProductOptionsElement;\n //make sure all the required options are selected\n if (optionsElement && !await optionsElement.reportValidity()) {\n return salla.error(salla.lang.get('common.messages.required_fields'));\n }\n\n //use this way to get quantity too\n let data = (this.host as any).getElementSallaData();\n\n // if the store doesn't have Apple Pay , just create a cart and then redirect to check out page\n if (!this.isApplePayActive) {\n // return salla.product.buyNow(this.productId, data);\n return salla.api.request('checkout/quick-purchase/' + this.productId, data, 'post')\n .then(resp => {\n if (resp.data.redirect) {\n window.location.href = resp.data.redirect;\n }\n return resp;\n });\n }\n data.is_applepay = true;\n\n if ('append' in data) {\n data.append('is_applepay', true);\n }\n\n // noinspection TypeScriptValidateJSTypes\n salla.event.dispatch('payments::apple-pay.start-transaction', {\n amount: this.amount, // 1000\n currency: this.currency || 'SAR', // SAR\n requiredShippingContactFields: this.isRequireShipping ? ['postalAddress'] : null,\n shippingMethods: this.isRequireShipping ? [] : null,\n supportedNetworks: salla.config.get('store.settings.buy_now.networks'),\n supportedCountries: salla.config.get('store.settings.buy_now.countries'),\n validateMerchant: {\n url: salla.url.get('checkout/applepay/validate'),\n onSuccess: () => {\n if (this.applePayOnly && !this.productId) { // the cart is not passes\n if (!this.cartId) {\n salla.logger.warn('🍏 Pay: trying to create applePay transaction without cartId/ProductId !');\n return;\n }\n window.SallaApplePay.id = this.cartId;\n salla.log('🍏 Pay: create checkout success: with id #' + this.cartId);\n return;\n\n }\n\n return salla.api.request('checkout/quick-purchase/' + this.productId, typeof data == 'object' ? data : undefined, 'post', {}).then(response => {\n\n // if is redirect url returned for any reason, lets redirect the user to check out\n if (response?.data?.redirect) {\n salla.log('🍏 Pay: create checkout success: redirect exits, go to checkout page');\n window.location.href = response.data.redirect.url;\n return response;\n }\n\n // the cart is not ready to complete apply pay session\n if (!response?.data?.id) {\n salla.logger.warn('🍏 Pay: create checkout success: No id, or redirect');\n return response;\n }\n\n window.SallaApplePay.id = response.data.id;\n\n salla.log('🍏 Pay: create checkout success: with id #' + window.SallaApplePay.id);\n });\n }\n },\n authorized: {\n // submit checkout route\n url: salla.url.get('checkout/{id}/payments/submit'),\n onFailed: (response) => {\n window.SallaApplePay.onCancel({}, response?.data?.error?.message || response?.data?.error?.code || salla.lang.get('pages.checkout.payment_failed'));\n },\n onSuccess: (response) => {\n window.location.href = response.redirect.url;\n salla.log('🍏 Pay: authorized Success:: redirect to thank you page, order placed');\n }\n },\n shippingMethodSelected: this.isRequireShipping ? {\n url: salla.url.get('checkout/{id}/shipping/details'),\n } : null,\n shippingContactSelected: this.isRequireShipping ? {\n url: salla.url.get('checkout/{id}/address/add'),\n } : null,\n oncouponcodechanged: {\n url: salla.url.get('checkout/{id}/coupons')\n },\n recalculateTotal: {\n url: salla.url.get('checkout/{id}/payments/recalculate')\n },\n onError: function (message) {\n salla.log(message);\n salla.notify.error(message);\n }\n });\n }\n\n componentWillLoad() {\n return new Promise((resolve, reject) => {\n salla.onReady(async () => {\n\n // if (!this.currency) {\n // this.currency = salla.config.get('user.currency_code');\n // }\n\n if (!this.productId && salla.config.get('page.id')) {\n this.productId = salla.config.get('page.id');\n }\n\n if (!this.applePayOnly && !this.productId) {\n salla.logger.warn('🍏 Pay: Failed load the quick buy, the product id is missing')\n return reject()\n }\n\n /**\n * We should check the product if it's required shipping\n * in order for apple pay sdk to show the required Shipping Contact Fields\n * components..\n */\n if ((!this.amount || !this.isRequireShipping) && this.productId) {\n await salla.product.getDetails(this.productId, []).then((response) => {\n this.amount = response.data.base_currency_price.amount;\n this.currency = response.data.base_currency_price.currency;\n this.isRequireShipping = response?.data?.is_require_shipping || false;\n }).catch((error) => {\n salla.logger.warn('🍏 Pay: Failed load the quick buy, get the product details failed: ', error)\n return reject()\n })\n }\n\n\n\n if (this.type == 'donate') {\n salla.event.on('product-options::donation-changed', (data) => {\n if (String(data.id) !== String(this.productId)) {\n return;\n }\n\n this.amount = data.price;\n });\n if (salla.url.is_page('product.single')) {\n salla.product.event?.onPriceUpdated(response => {\n this.currency = response.data.base_currency_price.currency;\n });\n }\n } else if (salla.url.is_page('product.single')) {\n salla.product.event?.onPriceUpdated(response => {\n this.amount = response.data.base_currency_price.amount;\n this.currency = response.data.base_currency_price.currency;\n });\n }\n this.isApplePayActive = window.ApplePaySession?.canMakePayments()\n && salla.config.get('store.settings.payments')?.includes('apple_pay')\n && salla.config.get('store.settings.is_salla_gateway', false);\n\n let applePaySdk = document.getElementById('apple-pay-sdk');\n if (applePaySdk || !this.isApplePayActive) {\n salla.logger.warn('🍏 Pay: Skipped load apple pay because ' + (applePaySdk ? 'already loaded' : 'is not available in the browser'))\n resolve(true);\n return;\n }\n\n const script = document.createElement('script');\n script.src = 'https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js';\n script.setAttribute('id', 'apple-pay-sdk');\n script.async = true;\n\n document.body.appendChild(script);\n\n resolve(true);\n })\n })\n }\n\n render() {\n return <Host>{this.quickBuyButton()}</Host>\n }\n\n private quickBuyButton() {\n return this.isApplePayActive\n ? <apple-pay-button locale={salla.config.get('user.language_code')}\n onClick={() => this.quickBuyHandler()}\n data-quick-purchase=\"applepay\"\n class=\"s-quick-buy-apple-pay\"\n data-is-applepay=\"1\"\n buttonstyle=\"black\"\n type={this.type} />\n :\n !this.applePayOnly ?<salla-button onClick={() => this.quickBuyHandler()}\n class=\"s-quick-buy-button\"\n color=\"primary\"\n fill=\"outline\"\n size=\"medium\"\n width=\"wide\"\n shape=\"btn\">\n <span innerHTML={FullWallet}/>\n {this.quickBuy}\n </salla-button>\n : '';\n }\n}\n"]}
1
+ {"version":3,"file":"salla-quick-buy.js","sourceRoot":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AC,wBAAkB,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAChE,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,eAAe,EAAE,yBACjB,UAAU,EAC9B,KAAK,EAAC,uBAAuB,sBACZ,GAAG,EACpB,WAAW,EAAC,OAAO,EACnB,IAAI,EAAE,IAAI,CAAC,IAAI,GAAI;MACrB,CAAC;QACD,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAA,oBAAc,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,eAAe,EAAE,EACzD,KAAK,EAAC,oBAAoB,EAC1B,KAAK,EAAC,SAAS,EACf,IAAI,EAAC,SAAS,EACd,IAAI,EAAC,QAAQ,EACb,KAAK,EAAC,MAAM,EACZ,KAAK,EAAC,KAAK;UACvB,YAAM,SAAS,EAAE,UAAU,GAAG;UAC7B,IAAI,CAAC,QAAQ,CACD;UACf,CAAC,CAAC,EAAE,CAAC;EACT,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Host, h, Prop, State, Element } from '@stencil/core';\nimport FullWallet from '../../assets/svg/full-wallet.svg';\nimport \"@salla.sa/applepay/src/index\";\n\n@Component({\n tag: 'salla-quick-buy',\n styleUrl: 'salla-quick-buy.scss',\n})\nexport class SallaQuickBuy {\n constructor() {\n salla.lang.onLoaded(() => {\n this.quickBuy = salla.lang.get('pages.products.buy_now');\n });\n\n if (salla.config.isGuest()) {\n let eventName = \"salla-quick-buy::user.logged-in\"\n salla.api.auth.setAfterLoginEvent(eventName)\n salla.event.on(eventName, () => this.settlePayment())\n }\n }\n\n @Element() host: HTMLElement;\n\n /**\n * Button type.\n *\n * @type {string}\n * @default buy\n **/\n @Prop({ mutable: true }) type: 'plain' | 'buy' | 'donate' | 'book' | 'pay' | 'order' = 'buy';\n\n /**\n * Product ID.\n *\n * @type {string}\n **/\n @Prop({ mutable: true }) productId: string;\n\n /**\n * Cart ID, when you need to applePay for existed cart\n *\n * @type {string}\n **/\n @Prop({ mutable: true }) cartId: string;\n\n /**\n * Product amount in base currency (SAR).\n *\n * @type {number}\n * @default 0\n **/\n @Prop({ reflect: true, mutable: true }) amount: number;\n\n /**\n * base currency\n *\n * @type {string}\n * @default SAR\n */\n @Prop({ mutable: true }) currency: string;\n\n /**\n * Product options, if is empty will get the data from the document.querySelector('salla-product-options[product-id=\"X\"]')\n *\n * @type {object}\n * @default {}\n */\n @Prop() options = {};\n\n /**\n * To be passed to purchaseNow request\n * @type {boolean}\n **/\n @Prop({mutable: true}) isRequireShipping: boolean;\n \n /**\n * Show Apple Pay only\n * @type {boolean}\n **/\n @Prop({mutable: true}) applePayOnly: boolean;\n\n @State() isApplePayActive: boolean;\n\n @State() quickBuy: string = salla.lang.get('pages.products.buy_now');\n\n private async quickBuyHandler() {\n if (salla.config.isGuest()) {\n // todo (low) :: find a way to re-fire the method after success\n return salla.auth.event.dispatch('login::open', { withoutReload: true });\n }\n await this.settlePayment()\n }\n\n private async settlePayment() {\n\n let optionsElement = document.querySelector(`salla-product-options[product-id=\"${this.productId}\"]`) as HTMLSallaProductOptionsElement;\n //make sure all the required options are selected\n if (optionsElement && !await optionsElement.reportValidity()) {\n return salla.error(salla.lang.get('common.messages.required_fields'));\n }\n\n //use this way to get quantity too\n let data = (this.host as any).getElementSallaData();\n\n // if the store doesn't have Apple Pay , just create a cart and then redirect to check out page\n if (!this.isApplePayActive) {\n // return salla.product.buyNow(this.productId, data);\n return salla.api.request('checkout/quick-purchase/' + this.productId, data, 'post')\n .then(resp => {\n if (resp.data.redirect) {\n window.location.href = resp.data.redirect;\n }\n return resp;\n });\n }\n data.is_applepay = true;\n\n if ('append' in data) {\n data.append('is_applepay', true);\n }\n\n // noinspection TypeScriptValidateJSTypes\n salla.event.dispatch('payments::apple-pay.start-transaction', {\n amount: this.amount, // 1000\n currency: this.currency || 'SAR', // SAR\n requiredShippingContactFields: this.isRequireShipping ? ['postalAddress'] : null,\n shippingMethods: this.isRequireShipping ? [] : null,\n supportedNetworks: salla.config.get('store.settings.buy_now.networks'),\n supportedCountries: salla.config.get('store.settings.buy_now.countries'),\n validateMerchant: {\n url: salla.url.get('checkout/applepay/validate'),\n onSuccess: (response) => {\n if (this.applePayOnly && !this.productId) { // the cart is not passes\n if (!this.cartId) {\n salla.logger.warn('🍏 Pay: trying to create applePay transaction without cartId/ProductId !');\n return response;\n }\n window.SallaApplePay.id = this.cartId;\n salla.log('🍏 Pay: create checkout success: with id #' + this.cartId);\n return response;\n\n }\n\n return salla.api.request('checkout/quick-purchase/' + this.productId, typeof data == 'object' ? data : undefined, 'post', {}).then(response => {\n\n // if is redirect url returned for any reason, lets redirect the user to check out\n if (response?.data?.redirect) {\n salla.log('🍏 Pay: create checkout success: redirect exits, go to checkout page');\n window.location.href = response.data.redirect.url;\n return response;\n }\n\n // the cart is not ready to complete apply pay session\n if (!response?.data?.id) {\n salla.logger.warn('🍏 Pay: create checkout success: No id, or redirect');\n return response;\n }\n\n window.SallaApplePay.id = response.data.id;\n\n salla.log('🍏 Pay: create checkout success: with id #' + window.SallaApplePay.id);\n });\n }\n },\n authorized: {\n // submit checkout route\n url: salla.url.get('checkout/{id}/payments/submit'),\n onFailed: (response) => {\n window.SallaApplePay.onCancel({}, response?.data?.error?.message || response?.data?.error?.code || salla.lang.get('pages.checkout.payment_failed'));\n },\n onSuccess: (response) => {\n window.location.href = response.redirect.url;\n salla.log('🍏 Pay: authorized Success:: redirect to thank you page, order placed');\n }\n },\n shippingMethodSelected: this.isRequireShipping ? {\n url: salla.url.get('checkout/{id}/shipping/details'),\n } : null,\n shippingContactSelected: this.isRequireShipping ? {\n url: salla.url.get('checkout/{id}/address/add'),\n } : null,\n oncouponcodechanged: {\n url: salla.url.get('checkout/{id}/coupons')\n },\n recalculateTotal: {\n url: salla.url.get('checkout/{id}/payments/recalculate')\n },\n onError: function (message) {\n salla.log(message);\n salla.notify.error(message);\n }\n });\n }\n\n componentWillLoad() {\n return new Promise((resolve, reject) => {\n salla.onReady(async () => {\n\n // if (!this.currency) {\n // this.currency = salla.config.get('user.currency_code');\n // }\n\n if (!this.productId && salla.config.get('page.id')) {\n this.productId = salla.config.get('page.id');\n }\n\n if (!this.applePayOnly && !this.productId) {\n salla.logger.warn('🍏 Pay: Failed load the quick buy, the product id is missing')\n return reject()\n }\n\n /**\n * We should check the product if it's required shipping\n * in order for apple pay sdk to show the required Shipping Contact Fields\n * components..\n */\n if ((!this.amount || !this.isRequireShipping) && this.productId) {\n await salla.product.getDetails(this.productId, []).then((response) => {\n this.amount = response.data.base_currency_price.amount;\n this.currency = response.data.base_currency_price.currency;\n this.isRequireShipping = response?.data?.is_require_shipping || false;\n }).catch((error) => {\n salla.logger.warn('🍏 Pay: Failed load the quick buy, get the product details failed: ', error)\n return reject()\n })\n }\n\n\n\n if (this.type == 'donate') {\n salla.event.on('product-options::donation-changed', (data) => {\n if (String(data.id) !== String(this.productId)) {\n return;\n }\n\n this.amount = data.price;\n });\n if (salla.url.is_page('product.single')) {\n salla.product.event?.onPriceUpdated(response => {\n this.currency = response.data.base_currency_price.currency;\n });\n }\n } else if (salla.url.is_page('product.single')) {\n salla.product.event?.onPriceUpdated(response => {\n this.amount = response.data.base_currency_price.amount;\n this.currency = response.data.base_currency_price.currency;\n });\n }\n this.isApplePayActive = window.ApplePaySession?.canMakePayments()\n && salla.config.get('store.settings.payments')?.includes('apple_pay')\n && salla.config.get('store.settings.is_salla_gateway', false);\n\n let applePaySdk = document.getElementById('apple-pay-sdk');\n if (applePaySdk || !this.isApplePayActive) {\n salla.logger.warn('🍏 Pay: Skipped load apple pay because ' + (applePaySdk ? 'already loaded' : 'is not available in the browser'))\n resolve(true);\n return;\n }\n\n const script = document.createElement('script');\n script.src = 'https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js';\n script.setAttribute('id', 'apple-pay-sdk');\n script.async = true;\n\n document.body.appendChild(script);\n\n resolve(true);\n })\n })\n }\n\n render() {\n return <Host>{this.quickBuyButton()}</Host>\n }\n\n private quickBuyButton() {\n return this.isApplePayActive\n ? <apple-pay-button locale={salla.config.get('user.language_code')}\n onClick={() => this.quickBuyHandler()}\n data-quick-purchase=\"applepay\"\n class=\"s-quick-buy-apple-pay\"\n data-is-applepay=\"1\"\n buttonstyle=\"black\"\n type={this.type} />\n :\n !this.applePayOnly ?<salla-button onClick={() => this.quickBuyHandler()}\n class=\"s-quick-buy-button\"\n color=\"primary\"\n fill=\"outline\"\n size=\"medium\"\n width=\"wide\"\n shape=\"btn\">\n <span innerHTML={FullWallet}/>\n {this.quickBuy}\n </salla-button>\n : '';\n }\n}\n"]}
@@ -2142,8 +2142,9 @@ window.SallaApplePay = {
2142
2142
  SallaApplePay.session.completeMerchantValidation(data.data);
2143
2143
  }
2144
2144
 
2145
- }, ({response}) => {
2146
- SallaApplePay.abortValidateMerchant(response);
2145
+ }, (error) => {
2146
+ console.error(error);
2147
+ SallaApplePay.abortValidateMerchant(error.response);
2147
2148
  });
2148
2149
  },
2149
2150
 
@@ -2470,15 +2471,15 @@ const SallaQuickBuy = /*@__PURE__*/ proxyCustomElement(class SallaQuickBuy exten
2470
2471
  supportedCountries: salla.config.get('store.settings.buy_now.countries'),
2471
2472
  validateMerchant: {
2472
2473
  url: salla.url.get('checkout/applepay/validate'),
2473
- onSuccess: () => {
2474
+ onSuccess: (response) => {
2474
2475
  if (this.applePayOnly && !this.productId) { // the cart is not passes
2475
2476
  if (!this.cartId) {
2476
2477
  salla.logger.warn('🍏 Pay: trying to create applePay transaction without cartId/ProductId !');
2477
- return;
2478
+ return response;
2478
2479
  }
2479
2480
  window.SallaApplePay.id = this.cartId;
2480
2481
  salla.log('🍏 Pay: create checkout success: with id #' + this.cartId);
2481
- return;
2482
+ return response;
2482
2483
  }
2483
2484
  return salla.api.request('checkout/quick-purchase/' + this.productId, typeof data == 'object' ? data : undefined, 'post', {}).then(response => {
2484
2485
  var _a, _b;