Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
4.3 kB
1
Indexable
Never
 const produceSubscriptionParams = (payment_response) => {

        let subscriptionParam = {
            'selectedOfferDetails': {
                'campaignId': formObj.campaignId || null,
                'rbItemId': formObj.rbItemId || null,
                'rbSubscriptionPlanId': formObj.subscriptionPlanId || null,
                'offerId': formObj.offerId || null,
                'bundleCatCd': formObj.bundleCatCd || null,
                'amount': formObj.subscription || null
            },
            'mailingAddress': {
                'addressLine1': formObj.MailingAddress1 || '',
                'addressLine2': formObj.MailingAddress2 || '',
                'city': formObj.MailingAddressCity || '',
                'state': formObj.MailingAddressState || '',
                'postalCode': formObj.MailingAddressZipCode || '',
                'country': formObj.MailingAddressCountry || ''
            }
        }

        switch (paymentType) {
            case 'creditcard':
                if (payment_response) {
                    subscriptionParam = {
                        ...subscriptionParam,
                        'paymentMethod': 1, // Mapping-> 1: Credit Card (Cybersource)
                        'creditCardPaymentDetails': {
                            'paymentToken': payment_response.token || null,
                            'cardHolderFirstName': formObj.FirstName || '',
                            'cardHolderLastName': formObj.LastName || '',
                            'cardLastFourDigits': payment_response ? Utils.getLastFourDigits(payment_response.maskedPan) : null,
                            'cvvCode': formObj.ccCvc ? formObj.ccCvc : null,
                            'expirationDate': formObj.ccExpMonth ? formObj.ccExpMonth + formObj.ccExpYear : null, // Format: MMyyyy
                            'cardType': payment_response ? parseInt(payment_response.cardType) : null, // Mapping-> 1: VISA, 2: MASTER, 3: AMERICAN EXPRESS, 4: DISCOVER
                            'isFlexMForm': true
                        },
                        'isAddressSame': sameAddressCheck ? true : false
                    }
                }
                break;
            case 'paypal':
                subscriptionParam = {
                    ...subscriptionParam,
                    'paymentMethod': 2, // Mapping-> 2: Paypal
                    'paypalPaymentDetails': {
                        'email': payment_response?.details?.email || null,
                        'firstName': payment_response?.details?.firstName || null,
                        'lastName': payment_response?.details?.lastName || null,
                        'payerId': payment_response?.details?.payerId || null,
                        'nonce': payment_response?.nonce || null
                    }
                }
                break;
            case 'gpay':
                subscriptionParam = {
                    ...subscriptionParam,
                    'paymentMethod': 3, // Mapping-> 3: Google Pay
                    'isAddressSame': true,
                    'digitalPaymentDetails': {
                        'token': payment_response
                    }                        
                }
                break;
            case 'applepay':
                subscriptionParam = {
                    ...subscriptionParam,
                    'paymentMethod': 6, // Mapping-> 5: Apple Pay, 6: Apple Pay Web
                    'isAddressSame': true,
                    'digitalPaymentDetails': {
                        'token': payment_response
                    }                        
                }
                break;
            default:
                break;
        }

        if (!sameAddressCheck) {
            subscriptionParam.billingAddress = {
                'addressLine1': formObj.BillingAddress1 || '',
                'addressLine2': formObj.BillingAddress2 || '',
                'city': formObj.BillingAddressCity || '',
                'state': formObj.BillingAddressState || '',
                'postalCode': formObj.BillingAddressZipCode || '',
                'country': formObj.BillingAddressCountry || ''
            }
        }

        return subscriptionParam;

    }