Skip to content

Commit

Permalink
file camelcase
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitdas13 committed Apr 28, 2022
1 parent b7c94db commit 6e1b136
Show file tree
Hide file tree
Showing 12 changed files with 1,227 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Razorpay.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

// Include Requests only if not already defined
$REQUESTS_SILENCE_PSR0_DEPRECATIONS = true;

if (class_exists('Requests') === false)
{
require_once __DIR__.'/libs/Requests-1.8.0/library/Requests.php';
require_once __DIR__.'/libs/Requests-2.0.0/src/Autoload.php';
}

try
{
Requests::register_autoloader();
WpOrg\Requests\Autoload::register();

if (version_compare(Requests::VERSION, '1.6.0') === -1)
{
Expand Down
130 changes: 130 additions & 0 deletions tests/PaperNachTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

namespace Razorpay\Tests;

use Razorpay\Api\Request;

class PaperNachTest extends TestCase
{
/**
* Specify unique customer id, invoice id , order id & token id
* for example cust_IEfAt3ruD4OEzo, inv_IF37M4q6SdOpjT,
* order_IF1TQZozl6Leaw & token_IF1ThOcFC9J7pU
*/

private $customerId = "cust_IEfAt3ruD4OEzo";

private $invoiceId = "inv_IF37M4q6SdOpjT";

private $orderId = "order_IF1TQZozl6Leaw";

private $tokenId = "token_IF1ThOcFC9J7pU";

public function setUp(): void
{
parent::setUp();
}

/**
* Create customer
*/
public function testCreateCustomerPaperNach()
{
$data = $this->api->customer->create(array('name' => 'Razorpay User 72', 'email' => '[email protected]', 'fail_existing'=>'0'));

$this->assertTrue(is_array($data->toArray()));

$this->assertTrue(in_array('customer',$data->toArray()));
}

/**
* Create Order
*/
public function testCreateOrderPaperNach()
{
$data = $this->api->order->create(array('receipt' => '123', 'amount' => 100, 'currency' => 'INR', 'notes'=> array('key1'=> 'value3','key2'=> 'value2')));

$this->assertTrue(is_array($data->toArray()));

$this->assertArrayHasKey('id',$data->toArray());
}

/**
* Send notification
*/
public function testSendNotification()
{
$data = $this->api->invoice->fetch($this->invoiceId)->notifyBy('email');

$this->assertTrue(in_array('success',$data));

}


/**
* Create registration link
*/
public function testRegistrationLink()
{
$data = $this->api->subscription->createSubscriptionRegistration(array('customer' => array('name' => 'Gaurav Kumar','email' => '[email protected]','contact' => '9123456780'),'amount' => 0,'currency' => 'INR','type' => 'link','description' => '12 p.m. Meals','subscription_registration' => array('method' => 'nach','auth_type' => 'physical','bank_account' => array('beneficiary_name' => 'Gaurav Kumar','account_number' => '11214311215411','account_type' => 'savings','ifsc_code' => 'HDFC0001233'),'nach' => array('form_reference1' => 'Recurring Payment for Gaurav Kumar','form_reference2' => 'Method Paper NACH'),'expire_at' => 1636772800,'max_amount' => 50000),'receipt' => 'Receipt No. '.time(),'sms_notify' => 1,'email_notify' => 1,'expire_by' => 1636772800,'notes' => array('note_key 1' => 'Beam me up Scotty','note_key 2' => 'Tea. Earl Gray. Hot.')));

$this->assertTrue(is_array($data->toArray()));

$this->assertTrue(in_array('id',$data->toArray()));
}

/**
* Fetch Payment ID using Order ID
*/
public function testFetchPaymentByorderId()
{
$data = $this->api->order->fetch($this->orderId)->payments();

$this->assertTrue(is_array($data->toArray()));

}

/**
* Fetch token by payment ID
*/
public function testFetchTokenByPaymentId()
{
$payment = $this->api->payment->all();

if(!empty($payment)){

$data = $this->api->payment->fetch($payment['items'][0]['id']);

$this->assertTrue(is_array($data->toArray()));

$this->assertArrayHasKey('id',$data->toArray());
}
}

/**
* Create an order to charge the customer
*/
public function testCreateOrderCharge()
{
$data = $this->api->order->create(array('receipt' => '122', 'amount' => 100, 'currency' => 'INR', 'notes'=> array('key1'=> 'value3','key2'=> 'value2')));

$this->assertTrue(is_array($data->toArray()));

$this->assertArrayHasKey('id',$data->toArray());
}

/**
* Create a Recurring Payment
*/
public function testCreateRecurring()
{
$order = $this->api->order->create(array("amount" => 100, "currency" => "INR","method" => "emandate", "payment_capture" => "1","customer_id" => $this->customerId ,"token" => array("auth_type" => "netbanking","max_amount" => 9999900,"expire_at" => 2147483647,"bank_account" => array("beneficiary_name" => "Gaurav Kumar","account_number" => "1121431121541121","account_type" => "savings","ifsc_code" => "HDFC0000001")
),"receipt" => "Receipt No. 1"));

$data = $this->api->payment->createRecurring(array('email'=>'[email protected]','contact'=>'9123456789','amount'=>100,'currency'=>'INR','order_id'=>$order->id,'customer_id'=>$this->customerId,'token'=>$this->tokenId,'recurring'=>'1','description'=>'Creating recurring payment for Gaurav Kumar'));

$this->assertTrue(is_array($data->toArray()));

}

}
188 changes: 188 additions & 0 deletions tests/PaymentLinkTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?php

namespace Razorpay\Tests;

use Razorpay\Api\Request;

class PaymentLinkTest extends TestCase
{
/**
* Specify unique paymentlink id
* for example plink_IEjOvfQs5AyjMN
*/
private $paymentLinkId = "plink_IEjOvfQs5AyjMN";

public function setUp(): void
{
parent::setUp();
}

/**
* Create Payment Link
*/
public function testCreatePaymentLink()
{
$data = $this->api->paymentLink->create(array('amount'=>500, 'currency'=>'INR', 'accept_partial'=>true,
'first_min_partial_amount'=>100, 'description' => 'For XYZ purpose', 'customer' => array('name'=>'Gaurav Kumar',
'email' => '[email protected]', 'contact'=>'+919999999999'), 'notify'=>array('sms'=>true, 'email'=>true) ,
'reminder_enable'=>true ,'notes'=>array('policy_name'=> 'Jeevan Bima'),'callback_url' => 'https://example-callback-url.com/',
'callback_method'=>'get'));

$this->cancelLinkId = $data->id;

$this->assertTrue(is_array($data->toArray()));

$this->assertTrue(in_array('accept_partial',$data->toArray()));
}

/**
* Fetch multiple refunds for a payment
*/
public function testFetchAllMutlipleRefund()
{
$data = $this->api->paymentLink->all();

$this->assertTrue(is_array($data->toArray()));

$this->assertTrue(is_array($data['payment_links']));
}

/**
* Fetch a specific refund for a payment
*/
public function testFetchRefund()
{
$data = $this->api->paymentLink->fetch($this->paymentLinkId);

$this->assertTrue(is_array($data->toArray()));

$this->assertTrue(in_array('amount',$data->toArray()));
}

/**
* Update Payment Link
*/
public function testUpdatePaymentLink()
{
$data = $this->api->paymentLink->fetch($this->paymentLinkId)->edit(array("reference_id"=>"TS".time(), "reminder_enable"=>0, "notes"=>["policy_name"=>"Jeevan Saral 2"]));

$this->assertTrue(is_array($data->toArray()));

$this->assertTrue(in_array('accept_partial',$data->toArray()));
}


/**
* Send notification
*/
public function testSendNotification()
{
$data = $this->api->paymentLink->fetch($this->paymentLinkId)->notifyBy('email');

$this->assertTrue(is_array($data));

$this->assertTrue(in_array('success',$data));
}

/**
* Cancel Payment Link
*/
public function testCancelPaymentLink()
{
$paymentLink = $this->api->paymentLink->create(array('amount'=>500, 'currency'=>'INR', 'accept_partial'=>true,
'first_min_partial_amount'=>100, 'description' => 'For XYZ purpose', 'customer' => array('name'=>'Gaurav Kumar',
'email' => '[email protected]', 'contact'=>'+919999999999'), 'notify'=>array('sms'=>true, 'email'=>true) ,
'reminder_enable'=>true ,'notes'=>array('policy_name'=> 'Jeevan Bima'),'callback_url' => 'https://example-callback-url.com/',
'callback_method'=>'get'));

$data = $this->api->paymentLink->fetch($paymentLink->id)->cancel();

$this->assertTrue(is_array($data->toArray()));

$this->assertTrue(in_array('accept_partial',$data->toArray()));
}

/**
* Transfer payments received using payment links
*/
public function testCreateTransferPayments()
{
$data = $this->api->paymentLink->create(array('amount'=>20000, 'currency'=>'INR', 'accept_partial'=>false, 'description' => 'For XYZ purpose', 'customer' => array('name'=>'Gaurav Kumar', 'email' => '[email protected]', 'contact'=>'+919999999999'), 'notify'=>array('sms'=>true, 'email'=>true) ,'reminder_enable'=>true , 'options'=>array('order'=>array('transfers'=>array('account'=>'acc_CPRsN1LkFccllA', 'amount'=>500, 'currency'=>'INR', 'notes'=>array('branch'=>'Acme Corp Bangalore North', 'name'=>'Bhairav Kumar' ,'linked_account_notes'=>array('branch'))), array('account'=>'acc_CNo3jSI8OkFJJJ', 'amount'=>500, 'currency'=>'INR', 'notes'=>array('branch'=>'Acme Corp Bangalore North', 'name'=>'Saurav Kumar' ,'linked_account_notes'=>array('branch')))))));

$this->assertTrue(is_array($data->toArray()));

$this->assertTrue(in_array('accept_partial',$data->toArray()));
}

/**
* Offers on payment links
*/
public function testOfferPaymentLinks()
{
$data = $this->api->paymentLink->create(array('amount'=>20000, 'currency'=>'INR', 'accept_partial'=>false, 'description' => 'For XYZ purpose', 'customer' => array('name'=>'Gaurav Kumar', 'email' => '[email protected]', 'contact'=>'+919999999999'), 'notify'=>array('sms'=>true, 'email'=>true) ,'reminder_enable'=>true , 'options'=>array('order'=>array('transfers'=>array('account'=>'acc_CPRsN1LkFccllA', 'amount'=>500, 'currency'=>'INR', 'notes'=>array('branch'=>'Acme Corp Bangalore North', 'name'=>'Bhairav Kumar' ,'linked_account_notes'=>array('branch'))), array('account'=>'acc_CNo3jSI8OkFJJJ', 'amount'=>500, 'currency'=>'INR', 'notes'=>array('branch'=>'Acme Corp Bangalore North', 'name'=>'Saurav Kumar' ,'linked_account_notes'=>array('branch')))))));

$this->assertTrue(is_array($data->toArray()));

$this->assertTrue(in_array('accept_partial',$data->toArray()));
}

/**
* Managing reminders for payment links
*/
public function testManagingRemainder()
{
$data = $this->api->paymentLink->create(array('amount'=>500, 'currency'=>'INR', 'accept_partial'=>true, 'first_min_partial_amount'=>100, 'description' => 'For XYZ purpose', 'customer' => array('name'=>'Gaurav Kumar', 'email' => '[email protected]', 'contact'=>'+919999999999'), 'notify'=>array('sms'=>true, 'email'=>true) ,'reminder_enable'=>false));

$this->assertTrue(is_array($data->toArray()));

$this->assertTrue(in_array('amount',$data->toArray()));
}

/**
* Rename labels in checkout section
*/
public function testRenameLabelsCheckout()
{
$data = $this->api->paymentLink->create(array('amount'=>500, 'currency'=>'INR', 'accept_partial'=>true, 'first_min_partial_amount'=>100, 'description' => 'For XYZ purpose', 'customer' => array('name'=>'Gaurav Kumar', 'email' => '[email protected]', 'contact'=>'+919999999999'), 'notify'=>array('sms'=>true, 'email'=>true) ,'reminder_enable'=>true , 'options'=>array('checkout'=>array('partial_payment'=>array('min_amount_label'=>'Minimum Money to be paid', 'partial_amount_label'=>'Pay in parts', 'partial_amount_description'=>'Pay at least ₹100', 'full_amount_label'=>'Pay the entire amount')))));

$this->assertTrue(is_array($data->toArray()));

$this->assertTrue(in_array('amount',$data->toArray()));
}

/**
* Change Business name
*/
public function testBusinessName()
{
$data = $this->api->paymentLink->create(array('amount'=>500, 'currency'=>'INR', 'accept_partial'=>true, 'first_min_partial_amount'=>100, 'description' => 'For XYZ purpose', 'customer' => array('name'=>'Gaurav Kumar', 'email' => '[email protected]', 'contact'=>'+919999999999'), 'notify'=>array('sms'=>true, 'email'=>true) ,'reminder_enable'=>true , 'options'=>array('checkout'=>array('name'=>'Lacme Corp'))));

$this->assertTrue(is_array($data->toArray()));

$this->assertTrue(in_array('accept_partial',$data->toArray()));
}

/**
* Change checkouts fields
*/
public function testCheckoutFields()
{
$data = $this->api->paymentLink->create(array('amount'=>500, 'currency'=>'INR', 'accept_partial'=>true, 'first_min_partial_amount'=>100, 'description' => 'For XYZ purpose', 'customer' => array('name'=>'Gaurav Kumar', 'email' => '[email protected]', 'contact'=>'+919999999999'), 'notify'=>array('sms'=>true, 'email'=>true) ,'reminder_enable'=>true , 'options'=>array('checkout'=>array('method'=>array('netbanking'=>'1', 'card'=>'1', 'upi'=>'0', 'wallet'=>'0')))));

$this->assertTrue(is_array($data->toArray()));

$this->assertTrue(in_array('accept_partial',$data->toArray()));
}

/**
* Rename labels in checkout section
*/
public function testRenameLabelsPayments()
{
$data = $this->api->paymentLink->create(array('amount'=>500, 'currency'=>'INR', 'accept_partial'=>true, 'first_min_partial_amount'=>100, 'description' => 'For XYZ purpose', 'customer' => array('name'=>'Gaurav Kumar', 'email' => '[email protected]', 'contact'=>'+919999999999'), 'notify'=>array('sms'=>true, 'email'=>true) ,'reminder_enable'=>true , 'options'=>array('hosted_page'=>array('label'=>array('receipt'=>'Ref No.'.time(), 'description'=>'Course Name', 'amount_payable'=>'Course Fee Payable', 'amount_paid'=>'Course Fee Paid', 'partial_amount_due'=>'Fee Installment Due', 'partial_amount_paid'=>'Fee Installment Paid', 'expire_by'=>'Pay Before', 'expired_on'=>'1632223497','amount_due'=>'Course Fee Due'), 'show_preferences'=>array('issued_to'=>false)))));

$this->assertTrue(is_array($data->toArray()));

$this->assertTrue(in_array('accept_partial',$data->toArray()));
}
}
Loading

0 comments on commit 6e1b136

Please sign in to comment.