razorpay / razorpay-php

Razorpay PHP Library
MIT License
186 stars 128 forks source link

payment link end point #233

Closed neera11 closed 3 years ago

isaumya commented 3 years ago

Hey @neera11, so if I am using this Razorpay PHP client to greater standard Payment Links, so, do I have to change the structure of the data that is passed? For example, current as per the readme example, it is stayed that I have to call the client the following way to create a payment link:

$link  = $api->invoice->create(
    arary(
        'type' => 'link', 
        'amount' => 500, 
        'description' => 'For XYZ purpose', 
        'customer' => array(
            'email' => 'test@test.test'
        )
    )
);

So, do I have to make any changes to this structure if I am only generating standard payment links?

neera11 commented 3 years ago

Hi @isaumya No need to pass type in Payment link call with invoice we were passing type as "link"

For payment link data will be

$orderData = json_encode( [ 'amount' => 98765, 'description' => 'For XYZ purpose', 'customer' => array('email' => 'test@test.test') ]);

$link = $api->payment_link->create($orderData, 'application/json' );

isaumya commented 3 years ago

Hi @neera11, Thanks for your reply. So, no we need to pass application/json as a second parameter to the create() function? As this was not there before.

I will highly recommend you to update the readme.md file with example of the new way of calling the API.

So, just to be clear, currently, I am doing the following for generating payment link:

// Include the composer autoload file
require_once( __DIR__ . '/../vendor/autoload.php' );

// Use Razorpay API
use Razorpay\Api\Api;

/**
 * Function to generate Razorpay Payment Link
 * @var $payment_dtls Array
 * @return $link Object
 */
function generate_payment_link( $payment_dtls ) {
  // Initiate New API
  $api = new Api( 'rzp_live_123456', 'abc123' );

  // Create Payment Link
  $link = $api->invoice->create(
    [
      'type'            =>  'link',
      'amount'          =>  ( $payment_dtls['amount'] * 100 ),
      'currency'        =>  $payment_dtls['currency'],
      'customer_id'     =>  $payment_dtls['cust_id'], // Customer ID
      'description'     =>  $payment_dtls['description'],
      'reminder_enable' =>  true,
      'expire_by'       =>  strtotime( $payment_dtls['expiry'] ) // Payment link will expire in X time from generation 
    ]
  );

  // Return the payment link details send by Razorpay after payment link creation
  return $link;
}

and once this new version of the package is released, it would done as following:

// Include the composer autoload file
require_once( __DIR__ . '/../vendor/autoload.php' );

// Use Razorpay API
use Razorpay\Api\Api;

/**
 * Function to generate Razorpay Payment Link
 * @var $payment_dtls Array
 * @return $link Object
 */
function generate_payment_link( $payment_dtls ) {
  // Initiate New API
  $api = new Api( 'rzp_live_123456', 'abc123' );

  // Create Payment Link
  $link = $api->payment_link->create(
    json_encode(
      [
        'amount'          =>  ( $payment_dtls['amount'] * 100 ),
        'currency'        =>  $payment_dtls['currency'],
        'customer_id'     =>  $payment_dtls['cust_id'], // Customer ID
        'description'     =>  $payment_dtls['description'],
        'reminder_enable' =>  true,
        'expire_by'       =>  strtotime( $payment_dtls['expiry'] ) // Payment link will expire in X time from generation 
      ]
    ),
    'application/json'
  );

  // Return the payment link details send by Razorpay after payment link creation
  return $link;
}

Right? Or I am missing/misunderstanding something here?

neera11 commented 3 years ago

Hi @isaumya You are using correctly , we need to pass second parameter as 'application/json' Is it woking fine for you or you getting any error? Will mention all these dependencies in readme.md file also

isaumya commented 3 years ago

Hi @neera11, I haven't tested the above code, I just modified the code to show you. I am not sure if I can test it until you guys release the update and I update the package via composer. I've running v2.7.0

isaumya commented 3 years ago

Hey @neera11, You still haven't updated the readme file which still suggests users to create the payment link in the old ways.

neera11 commented 3 years ago

Hi @isaumya sorry for the delay I have updated readme file. Please check

isaumya commented 3 years ago

Thanks, @neera11. Yes, I have checked. Now I am waiting for this PR to be accepted and pushing a new release with this code so that I can update the dependency and use the new methods.

isaumya commented 3 years ago

Hey @neera11, When is this getting released in a new version of the PHP client? As we have to update to the new endpoint by Aug 15, right? So, not many days left.

isaumya commented 3 years ago

@abhayp, @chirag-patel-rp please hurry up on pushing this release to the SDK as my account has been upgraded to using the new API and all of my automation system which is using the SDK might fail as I am not using the new API for payment link generation.

chirag-patel-rp commented 3 years ago

@isaumya contenty type relate comment is still not resolved @neera11 any update on that?

neera11 commented 3 years ago

@chirag-patel-rp @isaumya I have added content type related issue

neera11 commented 3 years ago

Hi @isaumya

We have updated the paymentlink. Now you don't need to pass second parameter as application/json while creating new paymentlink and also no need to pass data in json format. just use as below $link = $api->payment_link->create(array('amount' => 98765,'description' => 'For XYZ purpose', 'customer' => array('email' => 'test@test.test'))); // create payment link

Thank you

isaumya commented 3 years ago

Hi @neera11, Thank you so much for letting me know and also for releasing the update. Just have one small request, in the readme file for each call, please mention the respective API doc link for that call so that users can easily see what are the list of arguments that they can pass to that call. As in your example, you may have used a few parameters while I might use parameters like currency, cusermeID etc. So, if you guys provide a link to the API docs, users can easily see what they can pass to that call.

P.S.; Also in a future release, try testing your codebase in PHP 8, there are a few minor warnings in PHP 8 for the codebase.