@@ -45,62 +45,40 @@ let useAmazonPay = token => {
4545 canHandlePendingAuthorization : false ,
4646 },
4747 },
48- onInitCheckout : event => {
49- shippingAddressRef .current = event -> getShippingAddressFromEvent
50-
51- {
52- totalShippingAmount : {amount : defaultShippingAmount , currencyCode },
53- totalBaseAmount : {amount : sessionToken .totalBaseAmount , currencyCode },
54- totalTaxAmount : {amount : sessionToken .totalTaxAmount , currencyCode },
55- totalChargeAmount : {amount : totalOrderAmount , currencyCode },
56- totalDiscountAmount : {amount : "0.00" , currencyCode },
57- deliveryOptions : sessionToken .deliveryOptions ,
58- }
59- },
60- onShippingAddressSelection : event => {
61- shippingAddressRef .current = event -> getShippingAddressFromEvent
62-
63- {
64- totalShippingAmount : {amount : defaultShippingAmount , currencyCode },
65- totalBaseAmount : {amount : sessionToken .totalBaseAmount , currencyCode },
66- totalTaxAmount : {amount : sessionToken .totalTaxAmount , currencyCode },
67- totalChargeAmount : {amount : totalOrderAmount , currencyCode },
68- totalDiscountAmount : {amount : "0.00" , currencyCode },
69- deliveryOptions : sessionToken .deliveryOptions ,
70- }
71- },
72- onDeliveryOptionSelection : event => {
73- let selectedOption =
74- sessionToken .deliveryOptions -> Array .find (option => option .id === event .deliveryOptions .id )
75- let newShippingAmount = selectedOption -> Option .mapOr ("0.0" , option => option .price .amount )
76- let baseAmount = sessionToken .totalBaseAmount -> Float .fromString -> Option .getOr (0.0 )
77- let taxAmount = sessionToken .totalTaxAmount -> Float .fromString -> Option .getOr (0.0 )
78- let shippingAmount = newShippingAmount -> Float .fromString -> Option .getOr (0.0 )
79- let newTotalAmount = (baseAmount +. taxAmount +. shippingAmount )-> Float .toString
80-
81- {
82- totalShippingAmount : {amount : newShippingAmount , currencyCode },
83- totalBaseAmount : {amount : sessionToken .totalBaseAmount , currencyCode },
84- totalTaxAmount : {amount : sessionToken .totalTaxAmount , currencyCode },
85- totalChargeAmount : {amount : newTotalAmount , currencyCode },
86- totalDiscountAmount : {amount : "0.00" , currencyCode },
87- }
88- },
89- onCompleteCheckout : event => {
90- let amazonCheckoutSessionId =
91- event -> getDictFromJson -> getString ("amazonCheckoutSessionId" , "" )
92-
48+ onInitCheckout : e =>
49+ handleOnInitCheckout (
50+ e ,
51+ shippingAddressRef ,
52+ defaultShippingAmount ,
53+ currencyCode ,
54+ sessionToken ,
55+ totalOrderAmount ,
56+ ),
57+ onShippingAddressSelection : e =>
58+ handleOnShippingAddressSelection (
59+ e ,
60+ shippingAddressRef ,
61+ defaultShippingAmount ,
62+ currencyCode ,
63+ sessionToken ,
64+ totalOrderAmount ,
65+ ),
66+ onDeliveryOptionSelection : e =>
67+ handleOnDeliveryOptionSelection (e , currencyCode , sessionToken ),
68+ onCompleteCheckout : event =>
9369 intent (
94- ~bodyArr = amazonPayBody (amazonCheckoutSessionId , shippingAddressRef .current ),
70+ ~bodyArr = amazonPayBody (
71+ event -> getDictFromJson -> getString ("amazonCheckoutSessionId" , "" ),
72+ shippingAddressRef .current ,
73+ ),
9574 ~confirmParam = {
9675 return_url : options .wallets .walletReturnUrl ,
9776 publishableKey ,
9877 },
9978 ~handleUserError = true ,
10079 ~manualRetry = isManualRetryEnabled ,
101- )
102- },
103- onCancel : _ => {
80+ ),
81+ onCancel : _ =>
10482 intent (
10583 ~bodyArr = amazonPayBody ("" , shippingAddressRef .current ),
10684 ~confirmParam = {
@@ -109,8 +87,7 @@ let useAmazonPay = token => {
10987 },
11088 ~handleUserError = true ,
11189 ~manualRetry = isManualRetryEnabled ,
112- )
113- },
90+ ),
11491 }
11592 }
11693
0 commit comments