const FREE_PAYMENT_METHOD_NAME = 'FREE'; function freePaymentRequest() { var paymentRequest = { customerId: customerId, label: createLabelObject(), couponCode: discountCoupon.getCustomersCode(), standardNote: standardNote.getNoteAnswerObject(), selectedProductOption: selectedProductOption, selectedShippingMethod: selectedShippingMethod, selectedPaymentMethod: selectedPaymentMethod,//it will be better to integrate it more. shoppingCartId: shoppingCartId }; console.log('freePayment(): requesting charge with request ' + JSON.stringify(paymentRequest, null, 2)); return request.post('/beta/payment/freepay/charge') .set('X-Request-ID', correlationId) .send(paymentRequest); } function freePaymentProcess() { if (singleProductCheckout) { updateFunnelState(label, customerId, FUNNEL_STATES.PAYMENT_REQUESTED_BY_CUSTOMER).end(); updateFunnelState(label, customerId, FUNNEL_STATES.PAYMENT_INFO_COMPLETE).end(); } else { updateMultiFunnelState(customerId, FUNNEL_STATES.PAYMENT_REQUESTED_BY_CUSTOMER); updateMultiFunnelState(customerId, FUNNEL_STATES.PAYMENT_INFO_COMPLETE); } console.log('freePaymentProcess(): charging with payment method ' + selectedPaymentMethod); updateCustomer().end(); pay() } function putSelectedPaymentMethodAsFree() { selectedPaymentMethod = FREE_PAYMENT_METHOD_NAME; } function setupFree() { // 1) Handler for payment button (id podPaybutton) var freeButton = document.getElementById('freePaybutton'); freeButton.addEventListener('click', freePaymentProcess); console.log('setupFree(): Free payment method setup!'); } $(document).ready(function() { PAYMENT_METHOD_CHARGE_FUNCTIONS[FREE_PAYMENT_METHOD_NAME] = freePaymentRequest; });