-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
payment link end point #233
Conversation
Hey @neera11, $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? |
Hi @isaumya For payment link data will be $orderData = json_encode( $link = $api->payment_link->create($orderData, 'application/json' ); |
Hi @neera11, I will highly recommend you to update the 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? |
Hi @isaumya |
Hi @neera11, |
Hey @neera11, |
Hi @isaumya |
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. |
Hey @neera11, |
src/Entity.php
Outdated
* @param string $contentType | ||
* @return Payment_link | ||
*/ | ||
protected function create($attributes = null, $contentType= 'application/x-www-form-urlencoded') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why default content type is 'application/x-www-form-urlencoded'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are passing default as "application/x-www-form-urlencoded" and in case of payment link we need to pass "application/json" for that taking $contentType variable and passing default value as "application/x-www-form-urlencoded"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think clients should pass content type separately. Idea of sdk is using the functions without knowing the internals. it should be just paymentlink->create(attributes) imo. content type if required can be passed internally to the generic function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Entity.php
Outdated
{ | ||
$entityUrl = $this->getEntityUrl(); | ||
|
||
return $this->request('POST', $entityUrl, $attributes); | ||
return $this->request('POST', $entityUrl, $attributes,$contentType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting issue, space after comma
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok will do that
src/Request.php
Outdated
{ | ||
|
||
$ContentTypeHeader = array('Content-Type' => $contentType ); | ||
self::$headers = array_merge(self::$headers, $ContentTypeHeader); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting issue need extra line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Entity.php
Outdated
* | ||
* @param array $attributes | ||
* @param string $contentType | ||
* @return Payment_link |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not payment link class. why these comments?
src/Request.php
Outdated
@@ -153,12 +151,17 @@ protected function throwServerError($body, $httpStatusCode) | |||
$httpStatusCode); | |||
} | |||
|
|||
protected function getRequestHeaders() | |||
protected function getRequestHeaders($contentType = 'application/x-www-form-urlencoded') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are using only one content type everywhere? payment links will work with this content type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the default content type before? if we start passing default content type as above for all apis, will there be any issues for other functionalities?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abhayp, All of other RZP API is accepting POST request with Content-Type: application/x-www-form-urlencoded
then why payment Links not ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all out apis are json rest apis. we shouldnt ideally support application/x-www-form-urlencoded for json request. but since legacy code base is like that, we cannot remove it. for new ones we should enforce application/json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can release the new SDK version with application/json
@ramth05 do you see any challenges or drawbacks?
Anyway we want to move to application/json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chirag-patel-rp , don't see any issue as all our API supporting application/json
and no changes required by enduser . The only thing is that all the API end points we should test it before release new version. and if there is any corner case it should be handled.
e1b4300
to
53f3d9c
Compare
@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 @isaumya I have added content type related issue |
53f3d9c
to
ec60b44
Compare
src/Request.php
Outdated
{ | ||
if(isset($additionHeader)){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont check isset. it will always return true since the variable is set. check if(empty(additionHeader) === false please
@@ -153,12 +152,18 @@ protected function throwServerError($body, $httpStatusCode) | |||
$httpStatusCode); | |||
} | |||
|
|||
protected function getRequestHeaders() | |||
protected function getRequestHeaders($additionHeader) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add param type. this should always be an array. empty array for non pl
src/Entity.php
Outdated
@@ -7,12 +7,19 @@ | |||
class Entity extends Resource implements ArrayableInterface | |||
{ | |||
protected $attributes = array(); | |||
|
|||
private $additionHeader; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
follow how attributes are done please. this should be initialized as empty array
|
||
return $this->request('POST', $entityUrl, $attributes); | ||
return $this->request('POST', $entityUrl, $attributes, $this->additionHeader); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
additional header is passed here. cannot see the function param in request function
src/Entity.php
Outdated
@@ -83,10 +90,9 @@ protected function request($method, $relativeUrl, $data = null) | |||
{ | |||
$request = new Request(); | |||
|
|||
$response = $request->request($method, $relativeUrl, $data); | |||
$response = $request->request($method, $relativeUrl, $data, $this->additionHeader); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why pass the additional header from create function if u are referencing this here
src/Request.php
Outdated
@@ -37,7 +37,7 @@ class Request | |||
* @return array Response data in array format. Not meant | |||
* to be used directly | |||
*/ | |||
public function request($method, $url, $data = array()) | |||
public function request($method, $url, $data = array(),$additionHeader) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initialize as empty array please ..just like data
b914963
to
dce1111
Compare
dce1111
to
5ed1c1b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
|
||
$link = $api->payment_link->fetch('plink_GiwM9xbIZqbkJp'); // fetch payment link with id | ||
|
||
$data = json_encode( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@neera11, why we need to pass data as JSON for this entity only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep..should be array. @neera11
use Requests; | ||
|
||
|
||
class Payment_link extends Entity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@neera11 , why it's Payment_link
not PaymentLink
Hi @isaumya We have updated the paymentlink. Thank you |
Hi @neera11, 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. |
No description provided.