Repository URL to install this package:
|
Version:
1.3.3 ▾
|
import { isNonEmptyArray, isNil } from 'exotic'
import {
setShippingAddress,
updateShippingMethods,
getGuestProfile,
getSubmitOrder,
getPaymentFinal,
getPaymentAdd,
getPaymentDelete,
} from '../endpoints/cartAndCheckout/orchestration/requests'
import { transformAddPayment } from '../endpoints/cartAndCheckout/orchestration/transform'
/**
* @todo @bhargavi - add default `address` as empty if we don't pass it in
* (if it is an empty array in address)
* same as my account
*
* @see endpoints/user/defaultParams.js
*
*/
// @todo @bhargavi @move to typescript
// interface toAddPaymentParams {
// addCardDetailToProfile: Boolean = false;
// setAsDefaultCardInProfile: Boolean= false;
// useDefaultCard: Boolean = false;
// }
// const defaultAddPaymentParams {
// addCardDetailToProfile: false,
// setAsDefaultCardInProfile: false,
// useDefaultCard: false
// }
// function toAddPaymentParams(args: toAddPaymentParams= defaultAddPaymentParams) {
function toAddPaymentParams(args) {
const {
amount,
creditCard,
address,
addCardDetailToProfile,
setAsDefaultCardInProfile,
} = args
const addCardToProfile = addCardDetailToProfile ? addCardDetailToProfile : false
const setCardDefaultToProfile = setAsDefaultCardInProfile ? setAsDefaultCardInProfile : false
const useDefaultCard = false
console.log("Changed to typescript")
// isNil = isNullOrUndefined
const coercedAddress = isNil(address)
? address
: {
addressLine1: 'one%20front%20street',
addressLine2: '',
postalCode: '94111',
phone: '7845287100',
city: 'San Francisco',
state: 'CA',
firstName: 'raja',
lastName: 'raja',
country: 'US',
email: 'raja01@skava.com',
deliveryInstruction: '',
},
const customParams = {
useDefaultCard: [String(useDefaultCard)],
addCardDetailToProfile: [String(addCardToProfile)],
setAsDefaultCardInProfile: [String(setCardDefaultToProfile)],
}
const payment = {
type: 'creditcard',
address: [coercedAddress],
creditCard: creditCard,
amount,
customParams,
}
const paymentdetails = {
items: [
{
itemType: 'payment',
title: 'creditcard',
payment: payment,
},
],
}
const params = {
paymentdetails,
}
return params
}
export default {
Mutation: {
setShipping: async (obj, args, context, info) => {
const { shippingAddress } = args
const params = {
address: shippingAddress,
}
// const response = await setShippingAddress(params)
const response = await context.cartAndCheckout.setShippingAddress.forwardRequest(context).doRequest(params, undefined)
return response
},
updateShippingMethods: async (obj, args, context, info) => {
const { shippingMethod } = args
const payment = {
items: [
{
shippingDetails: [
{
shippingMethod,
},
],
},
],
}
const customParams = {
cartAction: 'load',
}
const params = {
payment: JSON.stringify(payment),
customparams: JSON.stringify(customParams),
}
// const response = await updateShippingMethods(params)
const response = await context.cartAndCheckout.updateShippingMethods.forwardRequest(context).doRequest(params, undefined)
return response
},
setGuestDetails: async (obj, args, context, info) => {
const { input } = args
const guestDetails = {
addresses: [input],
}
const params = {
item: guestDetails,
}
// const response = await getGuestProfile(params, undefined)
const response = await context.cartAndCheckout.getGuestProfile.forwardRequest(context).doRequest(params, undefined)
return response
},
addPaymentMethod: async (obj, args, context, info) => {
// const { paymentdetails } = args
// const params = {
// paymentdetails,
// }
const params = toAddPaymentParams(args.paymentdetails.items[0].payment)
// const response = await getPaymentAdd(params)
const response = await context.cartAndCheckout.getPaymentAdd.forwardRequest(context).doRequest(params, undefined)
const transformed = transformAddPayment(response)
return transformed
},
deletePaymentMethod: async (obj, args, context, info) => {
const { paymentdetails } = args
const params = {
// from jai
// item: paymentdetails.item,
// from michael
paymentdetails,
}
// const response = await getPaymentDelete(params)
const response = await context.cartAndCheckout.getPaymentDelete.forwardRequest(context).doRequest(params, undefined)
return response
},
submitOrder: async (obj, args, context, info) => {
// const response = await getSubmitOrder({}, undefined)
const response = await context.cartAndCheckout.getSubmitOrder.forwardRequest(context).doRequest({}, undefined)
return response
},
recalculateOrder: async (obj, args, context, info) => {
const { paymentdetails } = args
const params = {
paymentdetails,
}
// const response = await getPaymentFinal(params)
const response = await context.cartAndCheckout.getPaymentFinal.forwardRequest(context).doRequest(params, undefined)
return response
},
},
}