@@ -32,8 +32,6 @@ export type CheckoutState = {
32
32
billingAddress : ShippingAddress ,
33
33
} ;
34
34
35
- export const checkApplePay = ( ) => foxApi . applePay . available ( ) ;
36
-
37
35
export const selectCreditCard = createAction ( 'CHECKOUT_SET_CREDIT_CARD' ) ;
38
36
export const setEditStage = createAction ( 'CHECKOUT_SET_EDIT_STAGE' ) ;
39
37
export const setBillingData = createAction ( 'CHECKOUT_SET_BILLING_DATA' , ( key , value ) => [ key , value ] ) ;
@@ -43,6 +41,7 @@ export const setBillingAddress = createAction('CHECKOUT_SET_BILLING_ADDRESS');
43
41
export const toggleShippingModal = createAction ( 'TOGGLE_SHIPPING_MODAL' ) ;
44
42
export const toggleDeliveryModal = createAction ( 'TOGGLE_DELIVERY_MODAL' ) ;
45
43
export const togglePaymentModal = createAction ( 'TOGGLE_PAYMENT_MODAL' ) ;
44
+ const applePayAvailable = createAction ( 'APPLE_PAY_AVAILABLE' ) ;
46
45
const markAddressAsDeleted = createAction ( 'CHECKOUT_MARK_ADDRESS_AS_DELETED' ) ;
47
46
const markAddressAsRestored = createAction (
48
47
'CHECKOUT_MARK_ADDRESS_AS_RESTORED' ,
@@ -107,6 +106,36 @@ function addressToPayload(address) {
107
106
return payload ;
108
107
}
109
108
109
+ const _checkApplePay = createAsyncActions (
110
+ 'checkApplePay' ,
111
+ function ( ) {
112
+ const { dispatch } = this ;
113
+
114
+ return foxApi . applePay . available ( )
115
+ . then ( ( resp ) => {
116
+ dispatch ( applePayAvailable ( resp ) ) ;
117
+ } ) ;
118
+ }
119
+ ) ;
120
+
121
+ export const checkApplePay = _checkApplePay . perform ;
122
+
123
+ const _beginApplePay = createAsyncActions (
124
+ 'beginApplePay' ,
125
+ function ( payment ) {
126
+ return foxApi . applePay . beginApplePay ( payment )
127
+ . then ( ( ) => {
128
+ console . log ( 'payment is successfull, from checkout.js' ) ;
129
+ } )
130
+ . catch ( ( err ) => {
131
+ console . log ( 'error occurred in checkout.js, _beginApplePay' ) ;
132
+ throw new Error ( err ) ;
133
+ } ) ;
134
+ }
135
+ ) ;
136
+
137
+ export const beginApplePay = _beginApplePay . perform ;
138
+
110
139
const _removeShippingMethod = createAsyncActions (
111
140
'removeShippingMethod' ,
112
141
function ( ) {
@@ -465,6 +494,7 @@ const initialState: CheckoutState = {
465
494
shippingModalVisible : false ,
466
495
deliveryModalVisible : false ,
467
496
paymentModalVisible : false ,
497
+ applePayAvailable : false ,
468
498
} ;
469
499
470
500
function sortAddresses ( addresses : Array < Address > ) : Array < Address > {
@@ -505,6 +535,12 @@ const reducer = createReducer({
505
535
billingData,
506
536
} ;
507
537
} ,
538
+ [ applePayAvailable ] : ( state , available ) => {
539
+ return {
540
+ ...state ,
541
+ applePayAvailable : available ,
542
+ } ;
543
+ } ,
508
544
[ shippingMethodsActions . succeeded ] : ( state , list ) => {
509
545
return {
510
546
...state ,
0 commit comments