swell-js 4.0.7 → 4.0.8
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/dist/api.mjs +1 -1
- package/dist/payment.mjs +131 -37
- package/dist/swell.cjs +138 -44
- package/dist/swell.cjs.map +1 -1
- package/dist/swell.umd.min.js +87 -52
- package/dist/swell.umd.min.js.map +1 -1
- package/package.json +2 -1
- package/types/card/snake.d.ts +1 -0
- package/types/payment/snake.d.ts +11 -5
package/dist/api.mjs
CHANGED
package/dist/payment.mjs
CHANGED
|
@@ -326,7 +326,7 @@ class Payment {
|
|
|
326
326
|
/**
|
|
327
327
|
* Returns a cart.
|
|
328
328
|
*
|
|
329
|
-
* @returns {object}
|
|
329
|
+
* @returns {Promise<object>}
|
|
330
330
|
*/
|
|
331
331
|
async getCart() {
|
|
332
332
|
const cart = await methods(this.request, this.options).get();
|
|
@@ -342,7 +342,7 @@ class Payment {
|
|
|
342
342
|
* Updates a cart.
|
|
343
343
|
*
|
|
344
344
|
* @param {object} data
|
|
345
|
-
* @returns {object}
|
|
345
|
+
* @returns {Promise<object>}
|
|
346
346
|
*/
|
|
347
347
|
async updateCart(data) {
|
|
348
348
|
const updateData = cloneDeep(data);
|
|
@@ -367,7 +367,7 @@ class Payment {
|
|
|
367
367
|
/**
|
|
368
368
|
* Returns the store settings.
|
|
369
369
|
*
|
|
370
|
-
* @returns {object}
|
|
370
|
+
* @returns {Promise<object>}
|
|
371
371
|
*/
|
|
372
372
|
async getSettings() {
|
|
373
373
|
return methods$1(this.request, this.options).get();
|
|
@@ -377,7 +377,7 @@ class Payment {
|
|
|
377
377
|
* Creates a payment intent.
|
|
378
378
|
*
|
|
379
379
|
* @param {object} data
|
|
380
|
-
* @returns {object}
|
|
380
|
+
* @returns {Promise<object>}
|
|
381
381
|
*/
|
|
382
382
|
async createIntent(data) {
|
|
383
383
|
return this._vaultRequest('post', '/intent', data);
|
|
@@ -387,7 +387,7 @@ class Payment {
|
|
|
387
387
|
* Updates a payment intent.
|
|
388
388
|
*
|
|
389
389
|
* @param {object} data
|
|
390
|
-
* @returns {object}
|
|
390
|
+
* @returns {Promise<object>}
|
|
391
391
|
*/
|
|
392
392
|
async updateIntent(data) {
|
|
393
393
|
return this._vaultRequest('put', '/intent', data);
|
|
@@ -397,7 +397,7 @@ class Payment {
|
|
|
397
397
|
* Authorizes a payment gateway.
|
|
398
398
|
*
|
|
399
399
|
* @param {object} data
|
|
400
|
-
* @returns {object}
|
|
400
|
+
* @returns {Promise<object>}
|
|
401
401
|
*/
|
|
402
402
|
async authorizeGateway(data) {
|
|
403
403
|
return this._vaultRequest('post', '/authorization', data);
|
|
@@ -460,7 +460,7 @@ class Payment {
|
|
|
460
460
|
* Adjusts cart data.
|
|
461
461
|
*
|
|
462
462
|
* @param {object} cart
|
|
463
|
-
* @returns {object}
|
|
463
|
+
* @returns {Promise<object>}
|
|
464
464
|
*/
|
|
465
465
|
async _adjustCart(cart) {
|
|
466
466
|
return this._ensureCartSettings(cart).then(toSnake);
|
|
@@ -470,7 +470,7 @@ class Payment {
|
|
|
470
470
|
* Sets the store settings to cart.
|
|
471
471
|
*
|
|
472
472
|
* @param {object} cart
|
|
473
|
-
* @returns {object}
|
|
473
|
+
* @returns {Promise<object>}
|
|
474
474
|
*/
|
|
475
475
|
async _ensureCartSettings(cart) {
|
|
476
476
|
if (cart.settings) {
|
|
@@ -488,7 +488,7 @@ class Payment {
|
|
|
488
488
|
* @param {string} method
|
|
489
489
|
* @param {string} url
|
|
490
490
|
* @param {object} data
|
|
491
|
-
* @returns {object}
|
|
491
|
+
* @returns {Promise<object>}
|
|
492
492
|
*/
|
|
493
493
|
async _vaultRequest(method, url, data) {
|
|
494
494
|
const response = await vaultRequest(method, url, data);
|
|
@@ -539,6 +539,11 @@ class Payment {
|
|
|
539
539
|
}
|
|
540
540
|
}
|
|
541
541
|
|
|
542
|
+
/** @typedef {import('@stripe/stripe-js').Stripe} Stripe */
|
|
543
|
+
/** @typedef {import('@stripe/stripe-js').StripeCardElement} StripeCardElement */
|
|
544
|
+
/** @typedef {import('@stripe/stripe-js').StripeCardNumberElement} StripeCardNumberElement */
|
|
545
|
+
/** @typedef {import('@stripe/stripe-js').CreateSourceData} CreateSourceData */
|
|
546
|
+
|
|
542
547
|
// https://stripe.com/docs/currencies#minimum-and-maximum-charge-amounts
|
|
543
548
|
const MINIMUM_CHARGE_AMOUNT = {
|
|
544
549
|
USD: 0.5,
|
|
@@ -610,6 +615,10 @@ function getBillingDetails(cart) {
|
|
|
610
615
|
return details;
|
|
611
616
|
}
|
|
612
617
|
|
|
618
|
+
/**
|
|
619
|
+
* @param {CreateSourceData} source
|
|
620
|
+
* @param {object} data
|
|
621
|
+
*/
|
|
613
622
|
function setBancontactOwner(source, data) {
|
|
614
623
|
const fillValues = (fieldsMap, data) =>
|
|
615
624
|
reduce(
|
|
@@ -639,11 +648,17 @@ function setBancontactOwner(source, data) {
|
|
|
639
648
|
? { phone: billingData.phone }
|
|
640
649
|
: account.phone
|
|
641
650
|
? { phone: account.phone }
|
|
642
|
-
:
|
|
643
|
-
...(!isEmpty(billingAddress) ? { address: billingAddress } :
|
|
651
|
+
: undefined),
|
|
652
|
+
...(!isEmpty(billingAddress) ? { address: billingAddress } : undefined),
|
|
644
653
|
};
|
|
645
654
|
}
|
|
646
655
|
|
|
656
|
+
/**
|
|
657
|
+
* @param {string} type
|
|
658
|
+
* @param {import('@stripe/stripe-js').StripeElements} elements
|
|
659
|
+
* @param {object} params
|
|
660
|
+
* @returns {import('@stripe/stripe-js').StripeElement}
|
|
661
|
+
*/
|
|
647
662
|
function createElement(type, elements, params) {
|
|
648
663
|
const elementParams = params[type] || params;
|
|
649
664
|
const elementOptions = elementParams.options || {};
|
|
@@ -662,6 +677,11 @@ function createElement(type, elements, params) {
|
|
|
662
677
|
return element;
|
|
663
678
|
}
|
|
664
679
|
|
|
680
|
+
/**
|
|
681
|
+
* @param {Stripe} stripe
|
|
682
|
+
* @param {StripeCardElement | StripeCardNumberElement} cardElement
|
|
683
|
+
* @param {object} cart
|
|
684
|
+
*/
|
|
665
685
|
async function createPaymentMethod(stripe, cardElement, cart) {
|
|
666
686
|
const billingDetails = getBillingDetails(cart);
|
|
667
687
|
const { paymentMethod, error } = await stripe.createPaymentMethod({
|
|
@@ -678,18 +698,24 @@ async function createPaymentMethod(stripe, cardElement, cart) {
|
|
|
678
698
|
exp_month: paymentMethod.card.exp_month,
|
|
679
699
|
exp_year: paymentMethod.card.exp_year,
|
|
680
700
|
brand: paymentMethod.card.brand,
|
|
701
|
+
display_brand: paymentMethod.card.display_brand,
|
|
681
702
|
address_check: paymentMethod.card.checks.address_line1_check,
|
|
682
703
|
cvc_check: paymentMethod.card.checks.cvc_check,
|
|
683
|
-
zip_check: paymentMethod.card.checks.
|
|
704
|
+
zip_check: paymentMethod.card.checks.address_postal_code_check,
|
|
684
705
|
};
|
|
685
706
|
}
|
|
686
707
|
|
|
708
|
+
/**
|
|
709
|
+
* @param {Stripe} stripe
|
|
710
|
+
* @param {import('@stripe/stripe-js').StripeIdealBankElement} element
|
|
711
|
+
* @param {object} cart
|
|
712
|
+
*/
|
|
687
713
|
async function createIDealPaymentMethod(stripe, element, cart) {
|
|
688
714
|
const billingDetails = getBillingDetails(cart);
|
|
689
|
-
return
|
|
715
|
+
return stripe.createPaymentMethod({
|
|
690
716
|
type: 'ideal',
|
|
691
717
|
ideal: element,
|
|
692
|
-
...(billingDetails ? { billing_details: billingDetails } :
|
|
718
|
+
...(billingDetails ? { billing_details: billingDetails } : undefined),
|
|
693
719
|
});
|
|
694
720
|
}
|
|
695
721
|
|
|
@@ -712,6 +738,10 @@ function getKlarnaIntentDetails(cart) {
|
|
|
712
738
|
return details;
|
|
713
739
|
}
|
|
714
740
|
|
|
741
|
+
/**
|
|
742
|
+
* @param {object} cart
|
|
743
|
+
* @returns {import('@stripe/stripe-js').ConfirmKlarnaPaymentData}
|
|
744
|
+
*/
|
|
715
745
|
function getKlarnaConfirmationDetails(cart) {
|
|
716
746
|
const billingDetails = getBillingDetails(cart);
|
|
717
747
|
const returnUrl = `${
|
|
@@ -726,7 +756,12 @@ function getKlarnaConfirmationDetails(cart) {
|
|
|
726
756
|
};
|
|
727
757
|
}
|
|
728
758
|
|
|
759
|
+
/**
|
|
760
|
+
* @param {Stripe} stripe
|
|
761
|
+
* @param {object} cart
|
|
762
|
+
*/
|
|
729
763
|
async function createBancontactSource(stripe, cart) {
|
|
764
|
+
/** @type {CreateSourceData} */
|
|
730
765
|
const sourceObject = {
|
|
731
766
|
type: 'bancontact',
|
|
732
767
|
amount: Math.round(get(cart, 'grand_total', 0) * 100),
|
|
@@ -735,11 +770,17 @@ async function createBancontactSource(stripe, cart) {
|
|
|
735
770
|
return_url: window.location.href,
|
|
736
771
|
},
|
|
737
772
|
};
|
|
773
|
+
|
|
738
774
|
setBancontactOwner(sourceObject, cart);
|
|
739
775
|
|
|
740
|
-
return
|
|
776
|
+
return stripe.createSource(sourceObject);
|
|
741
777
|
}
|
|
742
778
|
|
|
779
|
+
/**
|
|
780
|
+
* @param {object} cart
|
|
781
|
+
* @param {object} params
|
|
782
|
+
* @returns {import('@stripe/stripe-js').PaymentRequestOptions}
|
|
783
|
+
*/
|
|
743
784
|
function getPaymentRequestData(cart, params) {
|
|
744
785
|
const {
|
|
745
786
|
currency,
|
|
@@ -802,29 +843,30 @@ function getPaymentRequestData(cart, params) {
|
|
|
802
843
|
};
|
|
803
844
|
}
|
|
804
845
|
|
|
846
|
+
const zeroDecimalCurrencies = new Set([
|
|
847
|
+
'BIF', // Burundian Franc
|
|
848
|
+
'DJF', // Djiboutian Franc,
|
|
849
|
+
'JPY', // Japanese Yen
|
|
850
|
+
'KRW', // South Korean Won
|
|
851
|
+
'PYG', // Paraguayan Guaraní
|
|
852
|
+
'VND', // Vietnamese Đồng
|
|
853
|
+
'XAF', // Central African Cfa Franc
|
|
854
|
+
'XPF', // Cfp Franc
|
|
855
|
+
'CLP', // Chilean Peso
|
|
856
|
+
'GNF', // Guinean Franc
|
|
857
|
+
'KMF', // Comorian Franc
|
|
858
|
+
'MGA', // Malagasy Ariary
|
|
859
|
+
'RWF', // Rwandan Franc
|
|
860
|
+
'VUV', // Vanuatu Vatu
|
|
861
|
+
'XOF', // West African Cfa Franc
|
|
862
|
+
]);
|
|
863
|
+
|
|
805
864
|
function stripeAmountByCurrency(currency, amount) {
|
|
806
|
-
|
|
807
|
-
'BIF', // Burundian Franc
|
|
808
|
-
'DJF', // Djiboutian Franc,
|
|
809
|
-
'JPY', // Japanese Yen
|
|
810
|
-
'KRW', // South Korean Won
|
|
811
|
-
'PYG', // Paraguayan Guaraní
|
|
812
|
-
'VND', // Vietnamese Đồng
|
|
813
|
-
'XAF', // Central African Cfa Franc
|
|
814
|
-
'XPF', // Cfp Franc
|
|
815
|
-
'CLP', // Chilean Peso
|
|
816
|
-
'GNF', // Guinean Franc
|
|
817
|
-
'KMF', // Comorian Franc
|
|
818
|
-
'MGA', // Malagasy Ariary
|
|
819
|
-
'RWF', // Rwandan Franc
|
|
820
|
-
'VUV', // Vanuatu Vatu
|
|
821
|
-
'XOF', // West African Cfa Franc
|
|
822
|
-
];
|
|
823
|
-
if (zeroDecimalCurrencies.includes(currency.toUpperCase())) {
|
|
865
|
+
if (zeroDecimalCurrencies.has(currency.toUpperCase())) {
|
|
824
866
|
return amount;
|
|
825
|
-
} else {
|
|
826
|
-
return Math.round(amount * 100);
|
|
827
867
|
}
|
|
868
|
+
|
|
869
|
+
return Math.round(amount * 100);
|
|
828
870
|
}
|
|
829
871
|
|
|
830
872
|
function isStripeChargeableAmount(amount, currency) {
|
|
@@ -832,6 +874,10 @@ function isStripeChargeableAmount(amount, currency) {
|
|
|
832
874
|
return !minAmount || amount >= minAmount;
|
|
833
875
|
}
|
|
834
876
|
|
|
877
|
+
/** @typedef {import('@stripe/stripe-js').Stripe} Stripe */
|
|
878
|
+
/** @typedef {import('@stripe/stripe-js').StripeCardElement} StripeCardElement */
|
|
879
|
+
/** @typedef {import('@stripe/stripe-js').StripeCardNumberElement} StripeCardNumberElement */
|
|
880
|
+
|
|
835
881
|
class StripeCardPayment extends Payment {
|
|
836
882
|
constructor(request, options, params, methods) {
|
|
837
883
|
super(request, options, params, methods.card);
|
|
@@ -841,6 +887,7 @@ class StripeCardPayment extends Payment {
|
|
|
841
887
|
return ['stripe-js'];
|
|
842
888
|
}
|
|
843
889
|
|
|
890
|
+
/** @returns {Stripe} */
|
|
844
891
|
get stripe() {
|
|
845
892
|
if (!StripeCardPayment.stripe) {
|
|
846
893
|
if (window.Stripe) {
|
|
@@ -855,14 +902,17 @@ class StripeCardPayment extends Payment {
|
|
|
855
902
|
return StripeCardPayment.stripe;
|
|
856
903
|
}
|
|
857
904
|
|
|
905
|
+
/** @param {Stripe} stripe */
|
|
858
906
|
set stripe(stripe) {
|
|
859
907
|
StripeCardPayment.stripe = stripe;
|
|
860
908
|
}
|
|
861
909
|
|
|
910
|
+
/** @returns {StripeCardElement | StripeCardNumberElement} */
|
|
862
911
|
get stripeElement() {
|
|
863
912
|
return StripeCardPayment.stripeElement;
|
|
864
913
|
}
|
|
865
914
|
|
|
915
|
+
/** @param {StripeCardElement | StripeCardNumberElement} stripeElement */
|
|
866
916
|
set stripeElement(stripeElement) {
|
|
867
917
|
StripeCardPayment.stripeElement = stripeElement;
|
|
868
918
|
}
|
|
@@ -1005,6 +1055,9 @@ class StripeCardPayment extends Payment {
|
|
|
1005
1055
|
}
|
|
1006
1056
|
}
|
|
1007
1057
|
|
|
1058
|
+
/** @typedef {import('@stripe/stripe-js').Stripe} Stripe */
|
|
1059
|
+
/** @typedef {import('@stripe/stripe-js').StripeIdealBankElement} StripeIdealBankElement */
|
|
1060
|
+
|
|
1008
1061
|
class StripeIDealPayment extends Payment {
|
|
1009
1062
|
constructor(request, options, params, methods) {
|
|
1010
1063
|
if (!methods.card) {
|
|
@@ -1023,6 +1076,7 @@ class StripeIDealPayment extends Payment {
|
|
|
1023
1076
|
return ['stripe-js'];
|
|
1024
1077
|
}
|
|
1025
1078
|
|
|
1079
|
+
/** @returns {Stripe} */
|
|
1026
1080
|
get stripe() {
|
|
1027
1081
|
if (!StripeIDealPayment.stripe) {
|
|
1028
1082
|
if (window.Stripe) {
|
|
@@ -1037,14 +1091,17 @@ class StripeIDealPayment extends Payment {
|
|
|
1037
1091
|
return StripeIDealPayment.stripe;
|
|
1038
1092
|
}
|
|
1039
1093
|
|
|
1094
|
+
/** @param {Stripe} stripe */
|
|
1040
1095
|
set stripe(stripe) {
|
|
1041
1096
|
StripeIDealPayment.stripe = stripe;
|
|
1042
1097
|
}
|
|
1043
1098
|
|
|
1099
|
+
/** @returns {StripeIdealBankElement} */
|
|
1044
1100
|
get stripeElement() {
|
|
1045
1101
|
return StripeIDealPayment.stripeElement;
|
|
1046
1102
|
}
|
|
1047
1103
|
|
|
1104
|
+
/** @param {StripeIdealBankElement} stripeElement */
|
|
1048
1105
|
set stripeElement(stripeElement) {
|
|
1049
1106
|
StripeIDealPayment.stripeElement = stripeElement;
|
|
1050
1107
|
}
|
|
@@ -1077,6 +1134,10 @@ class StripeIDealPayment extends Payment {
|
|
|
1077
1134
|
await this.stripe.handleCardAction(intent.client_secret);
|
|
1078
1135
|
}
|
|
1079
1136
|
|
|
1137
|
+
/**
|
|
1138
|
+
* @param {object} cart
|
|
1139
|
+
* @param {import('@stripe/stripe-js').PaymentMethod} paymentMethod
|
|
1140
|
+
*/
|
|
1080
1141
|
async _createIntent(cart, paymentMethod) {
|
|
1081
1142
|
const { currency, capture_total } = cart;
|
|
1082
1143
|
const stripeCurrency = (currency || 'EUR').toLowerCase();
|
|
@@ -1122,6 +1183,8 @@ class StripeIDealPayment extends Payment {
|
|
|
1122
1183
|
}
|
|
1123
1184
|
}
|
|
1124
1185
|
|
|
1186
|
+
/** @typedef {import('@stripe/stripe-js').Stripe} Stripe */
|
|
1187
|
+
|
|
1125
1188
|
class StripeBancontactPayment extends Payment {
|
|
1126
1189
|
constructor(request, options, params, methods) {
|
|
1127
1190
|
if (!methods.card) {
|
|
@@ -1140,6 +1203,7 @@ class StripeBancontactPayment extends Payment {
|
|
|
1140
1203
|
return ['stripe-js'];
|
|
1141
1204
|
}
|
|
1142
1205
|
|
|
1206
|
+
/** @returns {Stripe} */
|
|
1143
1207
|
get stripe() {
|
|
1144
1208
|
if (!StripeBancontactPayment.stripe) {
|
|
1145
1209
|
if (window.Stripe) {
|
|
@@ -1154,6 +1218,7 @@ class StripeBancontactPayment extends Payment {
|
|
|
1154
1218
|
return StripeBancontactPayment.stripe;
|
|
1155
1219
|
}
|
|
1156
1220
|
|
|
1221
|
+
/** @param {Stripe} stripe */
|
|
1157
1222
|
set stripe(stripe) {
|
|
1158
1223
|
StripeBancontactPayment.stripe = stripe;
|
|
1159
1224
|
}
|
|
@@ -1181,6 +1246,8 @@ class StripeBancontactPayment extends Payment {
|
|
|
1181
1246
|
}
|
|
1182
1247
|
}
|
|
1183
1248
|
|
|
1249
|
+
/** @typedef {import('@stripe/stripe-js').Stripe} Stripe */
|
|
1250
|
+
|
|
1184
1251
|
class StripeKlarnaPayment extends Payment {
|
|
1185
1252
|
constructor(request, options, params, methods) {
|
|
1186
1253
|
if (!methods.card) {
|
|
@@ -1199,6 +1266,7 @@ class StripeKlarnaPayment extends Payment {
|
|
|
1199
1266
|
return ['stripe-js'];
|
|
1200
1267
|
}
|
|
1201
1268
|
|
|
1269
|
+
/** @returns {Stripe} */
|
|
1202
1270
|
get stripe() {
|
|
1203
1271
|
if (!StripeKlarnaPayment.stripe) {
|
|
1204
1272
|
if (window.Stripe) {
|
|
@@ -1213,6 +1281,7 @@ class StripeKlarnaPayment extends Payment {
|
|
|
1213
1281
|
return StripeKlarnaPayment.stripe;
|
|
1214
1282
|
}
|
|
1215
1283
|
|
|
1284
|
+
/** @param {Stripe} stripe */
|
|
1216
1285
|
set stripe(stripe) {
|
|
1217
1286
|
StripeKlarnaPayment.stripe = stripe;
|
|
1218
1287
|
}
|
|
@@ -1271,6 +1340,9 @@ class StripeKlarnaPayment extends Payment {
|
|
|
1271
1340
|
}
|
|
1272
1341
|
}
|
|
1273
1342
|
|
|
1343
|
+
/** @typedef {import('@stripe/stripe-js').Stripe} Stripe */
|
|
1344
|
+
/** @typedef {import('@stripe/stripe-js').PaymentRequestPaymentMethodEvent} PaymentRequestPaymentMethodEvent */
|
|
1345
|
+
|
|
1274
1346
|
class StripeGooglePayment extends Payment {
|
|
1275
1347
|
constructor(request, options, params, methods) {
|
|
1276
1348
|
if (!methods.card) {
|
|
@@ -1289,6 +1361,7 @@ class StripeGooglePayment extends Payment {
|
|
|
1289
1361
|
return ['stripe-js'];
|
|
1290
1362
|
}
|
|
1291
1363
|
|
|
1364
|
+
/** @returns {Stripe} */
|
|
1292
1365
|
get stripe() {
|
|
1293
1366
|
if (!StripeGooglePayment.stripe) {
|
|
1294
1367
|
if (window.Stripe) {
|
|
@@ -1303,6 +1376,7 @@ class StripeGooglePayment extends Payment {
|
|
|
1303
1376
|
return StripeGooglePayment.stripe;
|
|
1304
1377
|
}
|
|
1305
1378
|
|
|
1379
|
+
/** @param {Stripe} stripe */
|
|
1306
1380
|
set stripe(stripe) {
|
|
1307
1381
|
StripeGooglePayment.stripe = stripe;
|
|
1308
1382
|
}
|
|
@@ -1360,6 +1434,7 @@ class StripeGooglePayment extends Payment {
|
|
|
1360
1434
|
return paymentRequest;
|
|
1361
1435
|
}
|
|
1362
1436
|
|
|
1437
|
+
/** @param {import('@stripe/stripe-js').PaymentRequestShippingAddressEvent} event */
|
|
1363
1438
|
async _onShippingAddressChange(event) {
|
|
1364
1439
|
const { shippingAddress, updateWith } = event;
|
|
1365
1440
|
const shipping = this._mapShippingAddress(shippingAddress);
|
|
@@ -1378,6 +1453,7 @@ class StripeGooglePayment extends Payment {
|
|
|
1378
1453
|
}
|
|
1379
1454
|
}
|
|
1380
1455
|
|
|
1456
|
+
/** @param {import('@stripe/stripe-js').PaymentRequestShippingOptionEvent} event */
|
|
1381
1457
|
async _onShippingOptionChange(event) {
|
|
1382
1458
|
const { shippingOption, updateWith } = event;
|
|
1383
1459
|
const cart = await this.updateCart({
|
|
@@ -1394,6 +1470,7 @@ class StripeGooglePayment extends Payment {
|
|
|
1394
1470
|
}
|
|
1395
1471
|
}
|
|
1396
1472
|
|
|
1473
|
+
/** @param {PaymentRequestPaymentMethodEvent} event */
|
|
1397
1474
|
async _onPaymentMethod(event) {
|
|
1398
1475
|
const {
|
|
1399
1476
|
payerEmail,
|
|
@@ -1421,6 +1498,7 @@ class StripeGooglePayment extends Payment {
|
|
|
1421
1498
|
gateway: 'stripe',
|
|
1422
1499
|
token: paymentMethod,
|
|
1423
1500
|
brand: card.brand,
|
|
1501
|
+
display_brand: card.display_brand,
|
|
1424
1502
|
exp_month: card.exp_month,
|
|
1425
1503
|
exp_year: card.exp_year,
|
|
1426
1504
|
last4: card.last4,
|
|
@@ -1436,8 +1514,11 @@ class StripeGooglePayment extends Payment {
|
|
|
1436
1514
|
this.onSuccess();
|
|
1437
1515
|
}
|
|
1438
1516
|
|
|
1439
|
-
|
|
1440
|
-
|
|
1517
|
+
/**
|
|
1518
|
+
* Provides backward compatibility with Google Pay button options
|
|
1519
|
+
*
|
|
1520
|
+
* @see {@link https://developers.google.com/pay/api/web/reference/request-objects#ButtonOptions}
|
|
1521
|
+
*/
|
|
1441
1522
|
_getButtonStyles() {
|
|
1442
1523
|
let { style: { color = 'dark', type = 'default', height = '45px' } = {} } =
|
|
1443
1524
|
this.params;
|
|
@@ -1467,6 +1548,7 @@ class StripeGooglePayment extends Payment {
|
|
|
1467
1548
|
};
|
|
1468
1549
|
}
|
|
1469
1550
|
|
|
1551
|
+
/** @param {import('@stripe/stripe-js').PaymentRequestShippingAddress} [address] */
|
|
1470
1552
|
_mapShippingAddress(address = {}) {
|
|
1471
1553
|
return {
|
|
1472
1554
|
name: address.recipient,
|
|
@@ -1480,6 +1562,7 @@ class StripeGooglePayment extends Payment {
|
|
|
1480
1562
|
};
|
|
1481
1563
|
}
|
|
1482
1564
|
|
|
1565
|
+
/** @param {PaymentRequestPaymentMethodEvent['paymentMethod']['billing_details']} [address] */
|
|
1483
1566
|
_mapBillingAddress(address = {}) {
|
|
1484
1567
|
return {
|
|
1485
1568
|
name: address.name,
|
|
@@ -1494,6 +1577,9 @@ class StripeGooglePayment extends Payment {
|
|
|
1494
1577
|
}
|
|
1495
1578
|
}
|
|
1496
1579
|
|
|
1580
|
+
/** @typedef {import('@stripe/stripe-js').Stripe} Stripe */
|
|
1581
|
+
/** @typedef {import('@stripe/stripe-js').PaymentRequestPaymentMethodEvent} PaymentRequestPaymentMethodEvent */
|
|
1582
|
+
|
|
1497
1583
|
class StripeApplePayment extends Payment {
|
|
1498
1584
|
constructor(request, options, params, methods) {
|
|
1499
1585
|
if (!methods.card) {
|
|
@@ -1512,6 +1598,7 @@ class StripeApplePayment extends Payment {
|
|
|
1512
1598
|
return ['stripe-js'];
|
|
1513
1599
|
}
|
|
1514
1600
|
|
|
1601
|
+
/** @returns {Stripe} */
|
|
1515
1602
|
get stripe() {
|
|
1516
1603
|
if (!StripeApplePayment.stripe) {
|
|
1517
1604
|
if (window.Stripe) {
|
|
@@ -1526,6 +1613,7 @@ class StripeApplePayment extends Payment {
|
|
|
1526
1613
|
return StripeApplePayment.stripe;
|
|
1527
1614
|
}
|
|
1528
1615
|
|
|
1616
|
+
/** @param {Stripe} stripe */
|
|
1529
1617
|
set stripe(stripe) {
|
|
1530
1618
|
StripeApplePayment.stripe = stripe;
|
|
1531
1619
|
}
|
|
@@ -1606,6 +1694,7 @@ class StripeApplePayment extends Payment {
|
|
|
1606
1694
|
return paymentRequest;
|
|
1607
1695
|
}
|
|
1608
1696
|
|
|
1697
|
+
/** @param {import('@stripe/stripe-js').PaymentRequestShippingAddressEvent} event */
|
|
1609
1698
|
async _onShippingAddressChange(event) {
|
|
1610
1699
|
const { shippingAddress, updateWith } = event;
|
|
1611
1700
|
const shipping = this._mapShippingAddress(shippingAddress);
|
|
@@ -1624,6 +1713,7 @@ class StripeApplePayment extends Payment {
|
|
|
1624
1713
|
}
|
|
1625
1714
|
}
|
|
1626
1715
|
|
|
1716
|
+
/** @param {import('@stripe/stripe-js').PaymentRequestShippingOptionEvent} event */
|
|
1627
1717
|
async _onShippingOptionChange(event) {
|
|
1628
1718
|
const { shippingOption, updateWith } = event;
|
|
1629
1719
|
const cart = await this.updateCart({
|
|
@@ -1640,6 +1730,7 @@ class StripeApplePayment extends Payment {
|
|
|
1640
1730
|
}
|
|
1641
1731
|
}
|
|
1642
1732
|
|
|
1733
|
+
/** @param {PaymentRequestPaymentMethodEvent} event */
|
|
1643
1734
|
async _onPaymentMethod(event) {
|
|
1644
1735
|
const {
|
|
1645
1736
|
payerEmail,
|
|
@@ -1667,6 +1758,7 @@ class StripeApplePayment extends Payment {
|
|
|
1667
1758
|
gateway: 'stripe',
|
|
1668
1759
|
token: paymentMethod,
|
|
1669
1760
|
brand: card.brand,
|
|
1761
|
+
display_brand: card.display_brand,
|
|
1670
1762
|
exp_month: card.exp_month,
|
|
1671
1763
|
exp_year: card.exp_year,
|
|
1672
1764
|
last4: card.last4,
|
|
@@ -1682,6 +1774,7 @@ class StripeApplePayment extends Payment {
|
|
|
1682
1774
|
this.onSuccess();
|
|
1683
1775
|
}
|
|
1684
1776
|
|
|
1777
|
+
/** @param {import('@stripe/stripe-js').PaymentRequestShippingAddress} [address] */
|
|
1685
1778
|
_mapShippingAddress(address = {}) {
|
|
1686
1779
|
return {
|
|
1687
1780
|
name: address.recipient,
|
|
@@ -1695,6 +1788,7 @@ class StripeApplePayment extends Payment {
|
|
|
1695
1788
|
};
|
|
1696
1789
|
}
|
|
1697
1790
|
|
|
1791
|
+
/** @param {PaymentRequestPaymentMethodEvent['paymentMethod']['billing_details']} [address] */
|
|
1698
1792
|
_mapBillingAddress(address = {}) {
|
|
1699
1793
|
return {
|
|
1700
1794
|
name: address.name,
|