Docs Discussion Login Register

Discussion

Start Discussion General Feature Module Dev Theme Dev Installation Hosting

Hi,

I am trying to create Razorpay payment gateway module, is there any doc available for that or if you can guide me the steps it would be very helpful to me in order to create the module. In order to use this Application i should have Razorpay payment gateway.


Thanks & Regards

Purvesh 1 year ago

Yes sorry for not having a docs available now. I am concentrating more into developing more feature and making the code base more stable. But definitely, I can give you an idea how you can implement custom payment gateway.

Step1: Execute an Module Create command first: 

php artisan avored:module:make Vendor Razorpay

Replace Vendor with your company name.

Open a register.yaml file and add below code (modules/company-name/razorpay/register.yaml):

status: Enabled
Name: Company Name Razorpay


Step2: Open an Module.php file: modules/company/razorpay/src/Module.php

public function boot()
{
$this->registerResources();// If you have any like below

/// Below code how to add Admin Configuration into AvoRed Admin --- You can add more too
$paymentGroup = AdminConfigurationFacade::get('payment');
$paymentGroup->addConfiguration('payment_razor_payment_enabled')
->label('Is RazorPay Enabled')
->type('select')
->name('payment_razor_payment_enabled')
->options(function () {
$options = [1 => 'Yes', 0 => 'No'];
return $options;
});

//Below is registering an PAyment Class for the Payment Gateway
$payment = new RazorPayPayment();
PaymentFacade::put($payment->identifier(), $payment);
}



Step 3: Create an RazorpayPayment class: (src/Payment/RazorpayPayment.php)


<?php

namespace AvoRed\RazorPay\Payment;

use AvoRed\Framework\Payment\Payment as AbstractPayment;
use AvoRed\Framework\Payment\Contracts\Payment as PaymentContract;
use AvoRed\Framework\Models\Database\Configuration;

class RazorPayPayment extends AbstractPayment implements PaymentContract
{
const CONFIG_KEY = 'payment_razor_payment_enabled';
/**
* Identifier for this Payment options.
*
* @var string
*/
protected $identifier = 'mycompany-razorpayment';
/**
* Title for this Payment options.
*
* @var string
*/
protected $name = 'RazorPay Payment';

/**
* Get Identifier for this Payment options.
*
* return string
*/
public function identifier()
{
return $this->identifier;
}
public function enable()
{
$isEnabled = Configuration::getConfiguration(self::CONFIG_KEY);
if (null === $isEnabled || false == $isEnabled) {
return false;
}
return true;
}
/**
* Get Title for this Payment Option.
*
* return boolean
*/
public function name()
{
return $this->name;
}
/*
* Process Payment Calculation
*
*/
public function process($orderData, $cartProducts, $request)
{
//EXECUTE API here if any??
return true;
}
}


yousuf patel 1 year ago

Hi Purvesh,

Thank you for the steps, by following the above steps i have created the razorpay module, but at front-end razorpay interface is something different with respect to the interface what you have made for strip, so i am little bit confuse with below points 

1) how to send the data to OrderController's place method

2) <script src="https://checkout.razorpay.com/v1/checkout.js"></script>

<script>

    $(document).ready(function () {


        var options = {

            "key": "rzp_test_cdlVnla....",

            "amount": "2000", // 2000 paise = INR 20

            "name": "Karvy Data Management Services Limited",

            "description": "Estore",

            "image": "https://karvyclick.com/website/images/karvyclick-logo.png",

            "handler": function (response) {

                alert(response.razorpay_payment_id);

            },

            "prefill": {

                "name": "Harshil Mathur",

                "email": "harshil@razorpay.com"

            },

            "notes": {

                "address": "Hello World"

            },

            "theme": {

                "color": "#F37254"

            }

        };

        var rzp1 = new Razorpay(options);



        jQuery('#razorpay').bind('paymentOptionChange', function (e) {


            if (jQuery(this).prop('id') != "razorpay") {


                return;

            }


            if (jQuery(e.target).is(":checked")) {

                rzp1.open();

                e.preventDefault();

            }


        });



    });




</script>


As you can see in above code i have to pass amount and customer details to payment gateway in view file itself , how can i achive this.

3) After implementing the module you can see the screens as attached  


yousuf patel 1 year ago


yousuf patel 1 year ago

Welcome to Razorpay Bank

This is just a demo bank page.
You can choose whether to make this payment successful or not: 

 

Purvesh 1 year ago

If I were you I would do simply one thing:

Just add simple jquery validation on the checkout page. If someone selects the Razorpay as a payment method(click on Radio button) in that event use jquery validation of the field that you required. If a customer doesn't fill up address details and click on Payment option first then display an error message or alert that Please fill address1,address2 or state and etc. 

yousuf patel 1 year ago

Hi Purvesh,

Thank you for your feedback , i have used the jquery validation and resolved the issue , but there is some problem after checkout in view order in front-end 

Order Basic Info

it is not showing the below listed 

Transaction No2
Shipping Method
Payment Method


 even if i done the payment using strip, can you please check it.

Thanks Yousuf.


yousuf patel 1 year ago

And one more thing you are not saving the payment ID in avored_orders table , which is the response from payment gateway, if you save it then it can be useful when any conflict.

And in strip payment gateway why you are using NZD as default currency symbol in Strip\Payment.php  with respect to below code ?

$response = Charge::create([

            'amount' => $totalCents,

            'currency' => 'nzd',

            'source' => $request->get('stripeToken'), // obtained with Stripe.js

            'description' => 'AvoRed E commerce Payment',

        ]);

 


  

Purvesh 1 year ago

I will double check that FrontEnd Order View Bug. I have added on my list.

And one more thing you are not saving the payment ID in an avored_orders table, which is the response from the payment gateway, if you save it then it can be used when any conflict.

I should be the responsibility of the Payment gateway because there is different response comes from all different kinds of payment so I think inside your Payment Gateway file you should store it into a DB.

And in strip payment gateway why you are using NZD as default currency symbol in Strip\Payment.php  with respect to below code?

I just changed it to my local copy but it has not been committed yet. 





yousuf patel 1 year ago

Thank you for your feedback, once you checked the  FrontEnd Order View Bug, please notify , so that i can update my local copy.

Purvesh 1 year ago

Just Reply the code into

Replace your stripe payment file code like below:


 $currencyCode = Configuration::getConfiguration('general_site_currency');

$response = Charge::create([
'amount' => $totalCents,
'currency' => $currencyCode,
'source' => $request->get('stripeToken'), // obtained with Stripe.js
'description' => 'AvoRed E commerce Payment',
]);


order view file:

<tr>
<th>Shipping Option</th>
<td>{{ $order->shipping_option }}</td>
</tr>
<tr>
<th>Payment Option</th>
<td>{{ $order->payment_option }}</td>
</tr>

yousuf patel 1 year ago

Hi Purvesh,


Thank you for your reply, in payment file if i access the value  $currencyCode = Configuration::getConfiguration('general_site_currency');

using above code, i will get the primary key of avored_site_currencies table, in order to get the CURRENCY CODE i have used the below code.

        $currency_id = Configuration::getConfiguration('general_site_currency');

        $currency = SiteCurrency::find($currency_id);

        $currencyCode = $currency->code; 


And used the model in payment file AvoRed\Ecommerce\Models\Database\SiteCurrency;

Please check the code and let me know am i right or wrong .

And one more thing if we have changed the Default Site Currency in configuration still i am seeing $ symbol for all products. 

Purvesh 1 year ago

Yes You right    


Reply
General Feature Module Dev Theme Dev Installation Hosting Save Cancel
© AvoRed 2019 Privacy