-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathUpiTest.php
139 lines (100 loc) · 4.92 KB
/
UpiTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
namespace Razorpay\Tests;
use Razorpay\Api\Request;
class UpiTest extends TestCase
{
/**
* Specify unique customer id, invoice id & order id
* for example cust_IEfAt3ruD4OEzo, inv_IEfS5mBV49bIQY &
* order_IEgBdwYACpMLxd
*/
private $customerId = "cust_IEfAt3ruD4OEzo";
private $invoiceId = "inv_IEfS5mBV49bIQY";
private $orderId = "order_IEgBdwYACpMLxd";
public function setUp(): void
{
parent::setUp();
}
/**
* Create customer
*/
public function testCreateCustomer()
{
$data = $this->api->customer->create(array('name' => 'Razorpay User 21', 'email' => '[email protected]','fail_existing'=>'0'));
$this->assertTrue(is_array($data->toArray()));
$this->assertTrue(in_array('customer',$data->toArray()));
}
/**
* Create Order
*/
public function testCreateOrder()
{
$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/Resend notifications
*/
public function testSendNotification()
{
$data = $this->api->invoice->fetch($this->invoiceId)->notifyBy('email');
$this->assertTrue(in_array('success',$data));
}
/**
* Create registration link
*/
public function testCreateSubscriptionRegistration()
{
$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()));
}
/**
* Cancel a registration link
*/
public function testCancelRegistrationLink()
{
$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.')));
$data = $this->api->invoice->fetch($data->id)->cancel();
$this->assertTrue(is_array($data->toArray()));
$this->assertTrue(in_array('invoice_number',$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 tokens by customer id
*/
public function testFetchTokenByCustomerId()
{
$data = $this->api->customer->fetch($this->customerId)->tokens()->all();
$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());
}
}