-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: update billing address before sendPayments (#31)
- Loading branch information
1 parent
ad12319
commit 893fa63
Showing
9 changed files
with
119 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,54 @@ | ||
import {AdyenPaymentsService} from '../../services/payments' | ||
import {AdyenPaymentsDetailsService} from '../../services/payments-details' | ||
export const baseConfig = (props) => { | ||
const onSubmit = async (state, component) => { | ||
try { | ||
if (!state.isValid) { | ||
throw new Error('invalid state') | ||
} | ||
const adyenPaymentService = new AdyenPaymentsService(props?.token) | ||
const paymentsResponse = await adyenPaymentService.submitPayment( | ||
state.data, | ||
props.basketId, | ||
props?.customerId | ||
) | ||
if (paymentsResponse?.isSuccessful) { | ||
props?.successHandler(paymentsResponse.merchantReference) | ||
} else if (paymentsResponse?.action) { | ||
await component.handleAction(paymentsResponse.action) | ||
} else { | ||
// handle error | ||
} | ||
} catch (error) { | ||
props?.errorHandler(error) | ||
} | ||
import {executeCallbacks} from '../../utils/executeCallbacks' | ||
|
||
export const baseConfig = ({ | ||
beforeSubmit = [], | ||
afterSubmit = [], | ||
beforeAdditionalDetails = [], | ||
afterAdditionalDetails = [], | ||
onError = (error) => { | ||
console.log(JSON.stringify(error)) | ||
}, | ||
...props | ||
}) => { | ||
return { | ||
onSubmit: executeCallbacks([...beforeSubmit, onSubmit, ...afterSubmit], props, onError), | ||
onAdditionalDetails: executeCallbacks( | ||
[...beforeAdditionalDetails, onAdditionalDetails, ...afterAdditionalDetails], | ||
props, | ||
onError | ||
) | ||
} | ||
} | ||
|
||
const onAdditionalDetails = async (state, component) => { | ||
try { | ||
const adyenPaymentsDetailsService = new AdyenPaymentsDetailsService(props?.token) | ||
const paymentsDetailsResponse = await adyenPaymentsDetailsService.submitPaymentsDetails( | ||
state.data, | ||
props?.customerId | ||
) | ||
if (paymentsDetailsResponse?.isSuccessful) { | ||
props?.successHandler(paymentsDetailsResponse.merchantReference) | ||
} else if (paymentsDetailsResponse?.action) { | ||
await component.handleAction(paymentsDetailsResponse.action) | ||
} else { | ||
// handle error | ||
} | ||
} catch (error) { | ||
props?.errorHandler(error) | ||
export const onSubmit = async (state, component, props) => { | ||
try { | ||
if (!state.isValid) { | ||
throw new Error('invalid state') | ||
} | ||
// await props.submitBilling() | ||
const adyenPaymentService = new AdyenPaymentsService(props?.token) | ||
const paymentsResponse = await adyenPaymentService.submitPayment( | ||
state.data, | ||
props.basketId, | ||
props?.customerId | ||
) | ||
return {paymentsResponse: paymentsResponse} | ||
} catch (error) { | ||
return new Error(error) | ||
} | ||
} | ||
|
||
return { | ||
onSubmit: onSubmit, | ||
onAdditionalDetails: onAdditionalDetails | ||
export const onAdditionalDetails = async (state, component, props) => { | ||
try { | ||
const adyenPaymentsDetailsService = new AdyenPaymentsDetailsService(props?.token) | ||
const paymentsDetailsResponse = await adyenPaymentsDetailsService.submitPaymentsDetails( | ||
state.data, | ||
props?.customerId | ||
) | ||
return {paymentsDetailsResponse: paymentsDetailsResponse} | ||
} catch (error) { | ||
return new Error(error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const executeCallbacks = (callbacks, props, onError) => { | ||
return async (...params) => { | ||
callbacks.reduce(async (data, func, index, arr) => { | ||
const next = await data | ||
const response = await func(...params, props, next) | ||
if (response instanceof Error) { | ||
onError(response) | ||
arr.splice(index) | ||
} | ||
return {...next, ...response} | ||
}, {}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters