-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmitpayment.php
More file actions
98 lines (79 loc) · 3.05 KB
/
Copy pathsubmitpayment.php
File metadata and controls
98 lines (79 loc) · 3.05 KB
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
<?php
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Methods:POST,GET,PUT,PATCH,DELETE');
header("Content-Type: application/json");
header("Accept: application/json");
header('Access-Control-Allow-Headers:Access-Control-Allow-Origin,Access-Control-Allow-Methods,Content-Type');
if (isset($_POST['action']) && $_POST['action'] = 'payOrder') {
$razorpay_mode = 'test';
$razorpay_test_key = 'rzp_test_bQIvnWckMpf3PG'; //Your Test Key
$razorpay_test_secret_key = 'dObvQngrKbuWPWII7HrvDAWL'; //Your Test Secret Key
$razorpay_live_key = 'Your_Live_Key';
$razorpay_live_secret_key = 'Your_Live_Secret_Key';
if ($razorpay_mode == 'test') {
$razorpay_key = $razorpay_test_key;
$authAPIkey = "Basic " . base64_encode($razorpay_test_key . ":" . $razorpay_test_secret_key);
} else {
$authAPIkey = "Basic " . base64_encode($razorpay_live_key . ":" . $razorpay_live_secret_key);
$razorpay_key = $razorpay_live_key;
}
// Set transaction details
$order_id = uniqid();
$billing_name = $_POST['billing_name'];
$billing_mobile = $_POST['billing_mobile'];
$billing_email = $_POST['billing_email'];
$shipping_name = $_POST['shipping_name'];
$shipping_mobile = $_POST['shipping_mobile'];
$shipping_email = $_POST['shipping_email'];
$paymentOption = $_POST['paymentOption'];
$payAmount = $_POST['payAmount'];
$note = "Payment of amount Rs. " . $payAmount;
$postdata = array(
"amount" => $payAmount * 100,
"currency" => "INR",
"receipt" => $note,
"notes" => array(
"notes_key_1" => $note,
"notes_key_2" => ""
)
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.razorpay.com/v1/orders',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode($postdata),
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Authorization: ' . $authAPIkey
),
));
$response = curl_exec($curl);
curl_close($curl);
$orderRes = json_decode($response);
if (isset($orderRes->id)) {
$rpay_order_id = $orderRes->id;
$dataArr = array(
'amount' => $payAmount,
'description' => "Pay bill of Rs. " . $payAmount,
'rpay_order_id' => $rpay_order_id,
'name' => $billing_name,
'email' => $billing_email,
'mobile' => $billing_mobile
);
echo json_encode(['res' => 'success', 'order_number' => $order_id, 'userData' => $dataArr, 'razorpay_key' => $razorpay_key]);
exit;
} else {
echo json_encode(['res' => 'error', 'order_id' => $order_id, 'info' => 'Error with payment']);
exit;
}
} else {
echo json_encode(['res' => 'error']);
exit;
}
?>