forked from razorpay/razorpay-php-testapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpay.php
executable file
·76 lines (59 loc) · 1.87 KB
/
pay.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
<?php
require('config.php');
require('razorpay-php/Razorpay.php');
session_start();
// Create the Razorpay Order
use Razorpay\Api\Api;
$api = new Api($keyId, $keySecret);
//
// We create an razorpay order using orders api
// Docs: https://docs.razorpay.com/docs/orders
//
$orderData = [
'receipt' => 3456,
'amount' => 2000 * 100, // 2000 rupees in paise
'currency' => 'INR',
'payment_capture' => 1 // auto capture
];
$razorpayOrder = $api->order->create($orderData);
$razorpayOrderId = $razorpayOrder['id'];
$_SESSION['razorpay_order_id'] = $razorpayOrderId;
$displayAmount = $amount = $orderData['amount'];
if ($displayCurrency !== 'INR')
{
$url = "https://api.fixer.io/latest?symbols=$displayCurrency&base=INR";
$exchange = json_decode(file_get_contents($url), true);
$displayAmount = $exchange['rates'][$displayCurrency] * $amount / 100;
}
$checkout = 'automatic';
if (isset($_GET['checkout']) and in_array($_GET['checkout'], ['automatic', 'manual'], true))
{
$checkout = $_GET['checkout'];
}
$data = [
"key" => $keyId,
"amount" => $amount,
"name" => "DJ Tiesto",
"description" => "Tron Legacy",
"image" => "https://s29.postimg.org/r6dj1g85z/daft_punk.jpg",
"prefill" => [
"name" => "Daft Punk",
"email" => "[email protected]",
"contact" => "9999999999",
],
"notes" => [
"address" => "Hello World",
"merchant_order_id" => "12312321",
],
"theme" => [
"color" => "#F37254"
],
"order_id" => $razorpayOrderId,
];
if ($displayCurrency !== 'INR')
{
$data['display_currency'] = $displayCurrency;
$data['display_amount'] = $displayAmount;
}
$json = json_encode($data);
require("checkout/{$checkout}.php");