Paypal + Afterpay + Apple Pay Submission
This commit is contained in:
parent
88dce0e67e
commit
5802ccead3
3 changed files with 88 additions and 10 deletions
|
|
@ -3,6 +3,7 @@ import store from "@/store";
|
|||
import globalMethods from "@/global-methods";
|
||||
import { endpoints } from "@/constants/endpoints";
|
||||
import { AppointmentTypeStrings } from "@/constants/schedule-constants";
|
||||
import { paymentMethods } from "@/constants/payment-method-constants";
|
||||
|
||||
export async function getNewSession(sessionConfig) {}
|
||||
|
||||
|
|
@ -69,6 +70,41 @@ export async function createAdyenCheckout({
|
|||
return await AdyenCheckout(config);
|
||||
}
|
||||
|
||||
export function mapAdyenToFmgPaymentMethod(adyenMethod) {
|
||||
const paymentMethodMap = {
|
||||
["scheme"]: paymentMethods.CREDIT_CARD,
|
||||
["afterpaytouch"]: paymentMethods.AFTERPAY,
|
||||
["paypal"]: paymentMethods.PAYPAL,
|
||||
["applepay"]: paymentMethods.APPLE_PAY,
|
||||
};
|
||||
|
||||
const match = paymentMethodMap[adyenMethod];
|
||||
|
||||
return match ?? paymentMethods.CREDIT_CARD;
|
||||
}
|
||||
|
||||
export function generateCcToken(adyenSessionInfo) {
|
||||
const order = store.getters.order;
|
||||
const locationInfo = getLocationInfo(order);
|
||||
|
||||
const ccToken = {
|
||||
subscriptionId: adyenSessionInfo?.storedToken,
|
||||
expMonth: adyenSessionInfo?.cardExpiryMonth,
|
||||
expYear: adyenSessionInfo?.cardExpiryYear,
|
||||
cardType: adyenSessionInfo?.cardType,
|
||||
billToPostalCode: locationInfo.zipCode, // TODO - real data?
|
||||
billToFirstName: order.customer.firstName, // TODO - real data?
|
||||
billToLastName: order.customer.lastName, // TODO - real data?
|
||||
referenceNumber: adyenSessionInfo?.workOrderNumber,
|
||||
authCode: adyenSessionInfo?.authCode,
|
||||
transactionId: adyenSessionInfo?.transactionReference,
|
||||
transReferenceNumber: adyenSessionInfo?.transactionReference,
|
||||
lastFour: adyenSessionInfo?.last4DigitsOfCard,
|
||||
};
|
||||
|
||||
return ccToken;
|
||||
}
|
||||
|
||||
function getLocationInfo(order) {
|
||||
const serviceLocation = order.serviceLocation;
|
||||
const isMobile = serviceLocation.appointmentType === AppointmentTypeStrings.MOBILE;
|
||||
|
|
|
|||
|
|
@ -22,13 +22,6 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<component
|
||||
:is="'script'"
|
||||
src="https://checkoutshopper-test.adyen.com/checkoutshopper/sdk/6.21.0/adyen.js"
|
||||
@load="initializeAdyen"></component>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://checkoutshopper-test.adyen.com/checkoutshopper/sdk/6.21.0/adyen.css" />
|
||||
</Form>
|
||||
</template>
|
||||
<script>
|
||||
|
|
@ -46,11 +39,13 @@ import baseMixin from "@/mixins/base-mixin.js";
|
|||
import { storeActions } from "@/constants/store-actions";
|
||||
import { getAmountDue } from "@/helpers/pricing-helper.js";
|
||||
import { submitWorkOrder } from "@/helpers/heritage-integration/order-helper.js";
|
||||
import { paymentMethods } from "@/constants/payment-method-constants";
|
||||
import { createAdyenCheckout } from "@/helpers/adyen-helper";
|
||||
import { Dropin } from "@adyen/adyen-web/auto";
|
||||
import { applicationConfig } from "@/constants/application-config";
|
||||
|
||||
import "@adyen/adyen-web/styles/adyen.css";
|
||||
import { mapAdyenToFmgPaymentMethod } from "../../helpers/adyen-helper";
|
||||
|
||||
export default {
|
||||
name: "payment-adyen",
|
||||
mixins: [],
|
||||
|
|
@ -225,12 +220,16 @@ export default {
|
|||
console.log(`CC Token generated =`);
|
||||
console.log(ccToken);
|
||||
|
||||
const paymentMethodFromSession = responseJson?.paymentMethod;
|
||||
|
||||
const paymentMethod = mapAdyenToFmgPaymentMethod(paymentMethodFromSession);
|
||||
|
||||
// Save payment type.
|
||||
// For now, CC.
|
||||
// Need to determine payment type from Adyen response
|
||||
await this.dispatchStoreAction(
|
||||
storeActions.SAVE_PAYMENT_METHOD_CHOICE,
|
||||
paymentMethods.CREDIT_CARD,
|
||||
paymentMethod,
|
||||
false
|
||||
);
|
||||
|
||||
|
|
@ -400,6 +399,10 @@ export default {
|
|||
},
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.initializeAdyen();
|
||||
},
|
||||
|
||||
components: {
|
||||
Form,
|
||||
funnelHeader,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
import { AdyenCheckout } from "@adyen/adyen-web";
|
||||
import { routeData } from "@/router/constants/routes";
|
||||
import { createAdyenCheckout, getSessionInfo } from "@/helpers/adyen-helper";
|
||||
import { mapAdyenToFmgPaymentMethod, generateCcToken } from "@/helpers/adyen-helper";
|
||||
import baseMixin from "@/mixins/base-mixin.js";
|
||||
import { getAmountDue } from "@/helpers/pricing-helper";
|
||||
import store from "@/store";
|
||||
import { storeActions } from "@/constants/store-actions";
|
||||
import { submitWorkOrder } from "@/helpers/heritage-integration/order-helper.js";
|
||||
|
||||
export async function adyenReturnBeforeEnter(to, from) {
|
||||
console.log(`In adyen return.`);
|
||||
|
|
@ -20,6 +25,40 @@ export async function adyenReturnBeforeEnter(to, from) {
|
|||
console.log(sessionInfo);
|
||||
|
||||
// TODO once afterpay info is returned, create cc token and submit order.
|
||||
const paymentMethod = mapAdyenToFmgPaymentMethod(sessionInfo?.paymentMethod);
|
||||
const amountDue = getAmountDue(store.getters.order.lineItems);
|
||||
const ccToken = generateCcToken(sessionInfo);
|
||||
|
||||
await baseMixin.methods.dispatchStoreAction(
|
||||
storeActions.SAVE_PAYMENT_METHOD_CHOICE,
|
||||
paymentMethod,
|
||||
false
|
||||
);
|
||||
|
||||
await baseMixin.methods.dispatchStoreAction(storeActions.SAVE_CCTOKEN, ccToken, false);
|
||||
|
||||
await baseMixin.methods.dispatchStoreAction(
|
||||
storeActions.SAVE_NEXTGEN_SETTLED_AMOUNT,
|
||||
amountDue,
|
||||
false
|
||||
);
|
||||
|
||||
await baseMixin.methods.dispatchStoreAction(storeActions.RESET_SAVE_SESSION_PROMISE);
|
||||
|
||||
try {
|
||||
await submitWorkOrder({
|
||||
pageNameToLog: "adyen-return",
|
||||
submitAfterSave: true,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return {
|
||||
name: routeData.ERROR.name,
|
||||
replace: true,
|
||||
};
|
||||
}
|
||||
|
||||
await baseMixin.methods.dispatchStoreAction(storeActions.CREATE_SUBMITTED_STATE);
|
||||
|
||||
return {
|
||||
name: routeData.CONFIRMATION.name,
|
||||
|
|
|
|||
Loading…
Reference in a new issue