cancel
Showing results for 
Search instead for 
Did you mean: 

Create custom payment module

Create custom payment module

Hi,

 

I would like to create a custom payment module which accept bin number only. It will also redirect user to payment gateway after selecting the payment method and click "Place Order". 

 

The payment method is showing on the checkout page but it is unable to save and place order therefore it is showing the following error

 

 

{message: "An error occurred on the server. Please try to place the order again.",…}
message
:
"An error occurred on the server. Please try to place the order again."
trace
:
"#0 C:\xampp\htdocs\storemena\shop\lib\internal\Magento\Framework\Interception\Interceptor.php(146): Magento\Checkout\Model\PaymentInformationManagement->savePaymentInformationAndPlaceOrder(61, Object(Magento\Quote\Model\Quote\Payment), Object(Magento\Quote\Model\Quote\Address))↵#1 C:\xampp\htdocs\storemena\shop\var\generation\Magento\Checkout\Model\PaymentInformationManagement\Interceptor.php(26): Magento\Checkout\Model\PaymentInformationManagement\Interceptor->___callPlugins('savePaymentInfo...', Array, Array)↵#2 [internal function]: Magento\Checkout\Model\PaymentInformationManagement\Interceptor->savePaymentInformationAndPlaceOrder(61, Object(Magento\Quote\Model\Quote\Payment), Object(Magento\Quote\Model\Quote\Address))↵#3 C:\xampp\htdocs\storemena\shop\app\code\Magento\Webapi\Controller\Rest.php(307): call_user_func_array(Array, Array)↵#4 C:\xampp\htdocs\storemena\shop\app\code\Magento\Webapi\Controller\Rest.php(216): Magento\Webapi\Controller\Rest->processApiRequest()↵#5 C:\xampp\htdocs\storemena\shop\var\generation\Magento\Webapi\Controller\Rest\Interceptor.php(37): Magento\Webapi\Controller\Rest->dispatch(Object(Magento\Framework\App\Request\Http))↵#6 C:\xampp\htdocs\storemena\shop\lib\internal\Magento\Framework\App\Http.php(135): Magento\Webapi\Controller\Rest\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))↵#7 C:\xampp\htdocs\storemena\shop\lib\internal\Magento\Framework\App\Bootstrap.php(258): Magento\Framework\App\Http->launch()↵#8 C:\xampp\htdocs\storemena\shop\index.php(48): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))↵#9 {main}"
Name

This isthe Javascript code in the Stripe/view/frontend/web/js/view/payment/method-renderer/stripe-method.js

 

define(
    [
        'underscore',
        'Magento_Checkout/js/view/payment/default',
        'ABC_Stripe/js/model/credit-card-validation/credit-card-data',
        'mage/url',
    ],
    function (_,Component, creditCardData, url) {
        'use strict';

        return Component.extend({
            defaults: {
                template: 'ABC_Stripe/payment/stripe-form',
                binNo:''
            },
            initObservable: function () {
                this._super()
                    .observe([
                        'binNo'
                    ]);

                return this;
            },
            initialize: function () {
                var self = this;

                this._super();

                //Set bin no to credit card data object
                this.binNo.subscribe(function (value) {
                    creditCardData.binNo = value;
                });
            },
            getCode: function() {
                return 'abc_stripe';
            },
            getData: function () {
                return {
                    'method': this.item.method,
                    'additional_data': {
                        'bin_num': this.binNo()
                    }
                };
            },
            isShowLegend: function () {
                return false;
            },
            isActive: function() {
                return true;
            },
            validate: function() {
                //Put your validation logic here
                return true;
            },
            afterPlaceOrder: function () {
                window.location.replace(url.build('stripe/payment/redirect/'));
            }
        });
    }
);

Javascript code in Stripe/view/base/web/js/model/credit-card-validation/credit-card-data.js.

 

/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
/*jshint browser:true jquery:true*/
/*global alert*/
define(
    [],
    function () {
        'use strict';

        return {
            binNo: null
        };
    }
);

Is there any thing that i miss in order to pass bin no into the payment method?