Adding new payment method in webstore frontend

Requirement:

  • In website, the custom payment option will be added on the Payment section in website.  
  • Need to create a new Terms named Stripe in NetSuite.  

Field Creation 

Customer Record 

  1. Check box field – We will need create a checkbox to identify whether the customer need stripe payment method or not? The stripe option should be display only if the option is enabled in the customer record.

Solution:

Add the stripe option in the checkout payment option by updating the paymentoption.invoice.js in orderwizard to show the stripe option in checkout pages.

var layout = container.getComponent('Layout');
var cart = container.getComponent('Cart');
                if (stripecheckboxval == 'T') {
                    _.extend(OrderWizardModulePaymentMethodInvoice.prototype, {
                        template: jj_customerregisterbydomain_customer_tpl,
                        events: {
                            'click [data-toggle="show-terms"]': 'showTerms',
                            'click [data-action="change-to-stripe"]': 'changetostripe'
                        },
                        changetostripe: function() {
                          //changeval = true;
                          this.model.attributes.changevales=true;
                            console.log("changeval", changeval)
                            if (this.isActive()) {
                                return this._render();
                            }
                        },
                        getProfile: function() {
                            return this.wizard.options.profile;
                        },
                        isActive: function() {
                            if (this.model.attributes.changevales == false) {
                                //console.log("outside click by dilse", changeval)
                                var terms = (this.terms = this.getProfile().get('paymentterms'));
                                var liveorder = LiveOrderModel.getInstance();
                                console.log("checking if liveorder model", liveorder.attributes.paymentmethods)

                            } else {
                                //console.log("inside click by dilse",changeval)
                                var terms = this.terms = {
                                    name: 'Stripe',
                                    internalid: '25'
                                };
                                var liveorder = LiveOrderModel.getInstance();
                                liveorder.attributes.paymentmethods.Stripe = true;
                                //console.log("checking liveorder model",liveorder)
                            }                           
                            return terms && terms.internalid;
                        },
                        submit: function() {
                            var self = this;
                            if (this.model.attributes.changevales == false) {
                                return this.isValid().done(function() {
                                    self.paymentMethod = new TransactionPaymentmethodModel({
                                        type: 'invoice',
                                        terms: self.wizard.options.profile.get('paymentterms')
                                    });

                                    OrderWizardModulePaymentMethod.prototype.submit.apply(self);
                                });
                            } else {
                                return this.isValid().done(function() {
                                    self.paymentMethod = new TransactionPaymentmethodModel({
                                        type: 'invoice',
                                        terms: {
                                            name: 'Stripe',
                                            internalid: '25'
                                        },
                                        Stripe: true

                                    });
                                    self.model.set('Stripe', true)


                                    var liveorder = LiveOrderModel.getInstance();
                                    var websubtotal = liveorder.attributes.summary.subtotal;
                                    var editsubtotal = websubtotal - (websubtotal * 0.25);
                                    var data = {
                                        fieldId: "custbody_enablestripe",
                                        type: "boolean",
                                        value: true
                                    }

                                    var data2 = {
                                        fieldId: "custbody_srtipesubtotal",
                                        type: "number",
                                        value: editsubtotal
                                    }


                                   // data.push(data2);
                                    console.log("data", data)
                                    cart.setTransactionBodyField(data).then(function() {
                                        console.log(data.fieldId + ' was set to ' + data.value);
                                    }).fail(function(error) {
                                        console.log('setTransactionBodyField failed.');
                                    });
                                    cart.setTransactionBodyField(data2).then(function() {
                                        console.log(data2.fieldId + ' was set to ' + data2.value);
                                    }).fail(function(error) {
                                        console.log('setTransactionBodyField failed.');
                                    });
                                   // self.model.set('options',{custbody_enablestripe:'T',custbody_srtipesubtotal:editsubtotal})
                                                   
                                    OrderWizardModulePaymentMethod.prototype.submit.apply(self);

                                });
                            }
                        }
                        //})
                    });
}
<div class="order-wizard-paymentmethod-invoice-module">
	<div class="order-wizard-paymentmethod-invoice-module-row">
		<div class="order-wizard-paymentmethod-invoice-module-terms">

			<p class="order-wizard-paymentmethod-invoice-module-terms-label">
				{{translate 'Terms'}}
			</p>
			<p class="order-wizard-paymentmethod-invoice-module-terms-value">
				{{termsName}}
			</p>			
		</div>			
		<div class="order-wizard-paymentmethod-invoice-module-balance">
			<p class="order-wizard-paymentmethod-invoice-module-balance-label">
				{{translate 'Available Balance'}}
			</p>
			<p class="order-wizard-paymentmethod-invoice-module-balance-value">
				{{balanceAvailable}}
			</p>
		</div>
	</div>
	{{#if showstripesbutton}}
<div class="orderwizard-button-stripe-main">
			<!--  -->
			<button class="orderwizard-button-stripe {{#if colorval}}testname{{/if}}" data-action="change-to-stripe"> Stripe</button>
	</div>
			{{/if}}
	{{#if showTerms}}
		<p class="order-wizard-paymentmethod-invoice-module-conditions">
			{{translate 'I agree to pay with my current Invoice <a data-toggle="show-terms" href="#">Terms & Conditions</a>'}}
		</p>
	{{/if}}
</div>

Leave a comment

Your email address will not be published. Required fields are marked *