· last year · Oct 15, 2023, 04:00 PM
1Developer API:
2
3PHP
4
5 // Set the API endpoint URL
6 $url = 'https://esmartgate.com/paypal';
7
8 // Set API key, amount, customer email, number ID, visitor IP, user agent, return URL, cancel URL, sandbox flag
9 $api = 'YOUR_API_KEY';
10 $amount = 100.0; // Replace with your desired amount
11 $email = 'customer@example.com'; // Replace with the customer's email
12 $item_number = 12345; // Replace with the NumberID from your website
13 $visitor_ip = $_SERVER['REMOTE_ADDR']; // Replace with the customer's IP address
14 $user_agent = $_SERVER['HTTP_USER_AGENT']; // Get the user agent of the customer's browser
15 $return_url = 'your_website.com/return_url'; // Replace with your return URL
16 $cancel_url = 'your_website.com/cancel_url'; // Replace with your cancel URL
17 $sandbox = 1; // Set to 1 if you want to use the sandbox
18
19 // Prepare the POST data
20 $data = array(
21 'api' => $api,
22 'amount' => $amount,
23 'email' => $email,
24 'item_number' => $item_number,
25 'visitor_ip' => $visitor_ip,
26 'user_agent' => $user_agent,
27 'return' => $return_url,
28 'cancel_return' => $cancel_url,
29 'sandbox' => $sandbox,
30 );
31
32 // Set the HTTP_REFERER header
33 $referer_url = 'https://your_website'; // Replace with the actual previous page URL
34 $http_referer_header = 'Referer: ' . $referer_url;
35
36 // Initialize cURL session
37 $ch = curl_init();
38
39 // Set cURL options for POST request
40 curl_setopt($ch, CURLOPT_URL, $url);
41 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
42 curl_setopt($ch, CURLOPT_POST, true);
43 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
44
45 // Set the HTTP_REFERER header
46 curl_setopt($ch, CURLOPT_HTTPHEADER, array($http_referer_header));
47
48 // Execute cURL session and get the response
49 $response = curl_exec($ch);
50
51 // Check for cURL errors
52 if (curl_errno($ch)) {
53 echo 'cURL error: ' . curl_error($ch);
54 }
55
56 // Close cURL session
57 curl_close($ch);
58
59 // Process the response, if needed
60 // For example, you can parse the JSON response or display it on your page
61 echo $response;
62
63Python
64
65 pip install user_agent
66
67 import requests
68 from user_agent import generate_user_agent
69 import socket
70
71 # Set the API endpoint URL
72 url = 'https://esmartgate.com/paypal'
73
74 # Set your API key, amount, customer email, number ID, return URL, cancel URL, and sandbox flag
75 api = 'YOUR_API_KEY'
76 amount = 100.0 # Replace with your desired amount
77 email = 'customer@example.com' # Replace with the customer's email
78 item_number = 12345 # Replace with the NumberID from your website
79 return_url = 'your_website.com/return_url' # Replace with your return URL
80 cancel_url = 'your_website.com/cancel_url' # Replace with your cancel URL
81
82 # Auto-detect the user agent
83 user_agent = generate_user_agent()
84
85 # Auto-detect the visitor's IP address
86 visitor_ip = socket.gethostbyname(socket.gethostname())
87
88 # Set the headers with the Referer
89 headers = {
90 'Referer': 'your_website', # Replace with the actual previous page URL
91 'User-Agent': user_agent
92 }
93
94 # Prepare the POST data
95 data = {
96 'api': api,
97 'amount': amount,
98 'email': email,
99 'item_number': item_number,
100 'visitor_ip': visitor_ip,
101 'user_agent': user_agent,
102 'return': return_url,
103 'cancel_return': cancel_url,
104 'sandbox': sandbox,
105 }
106
107 # Send the POST request
108 response = requests.post(url, data=data, headers=headers)
109
110 # Check if the request was successful
111 if response.status_code == 200:
112 print('Request successful:')
113 print(response.text)
114 else:
115 print('Request failed with status code:', response.status_code)
116
117RESPONSE
118
119 Success
120
121 {"status":true,"message":"The payment link has been sent to your email: customer@example.com, please check it."}
122
123
124 False
125
126 {"status":false,"message":"Parameter error, Please try again!"}
127
128
129 Error
130
131 {"status":false,"message":"Payment has been declined. Please try again."}
132
133POST to your NOTIFY URL
134POST https://your_website.com/callback
135 Array
136 (
137 'status' => completed | refunded,
138 'payer_email' => customer_email,
139 'txn_id' => item_number,
140 'mc_gross' => order_amount,
141 'SignatureValue' => SignatureValue,
142 )
143 $receivedTransaction = $_POST;
144 $salt = "YOUR_API";
145 $receivedHash = $receivedTransaction['SignatureValue'];
146 unset($receivedTransaction['SignatureValue']);
147
148 $stringData = json_encode($receivedTransaction);
149 $computedHash = hash('sha256', $stringData . $salt);
150
151 // Verify the hash
152 if ($computedHash === $receivedHash) {
153 // Hashes match, data is untampered
154 // Continue processing...
155 } else {
156 // Hashes do not match, potential data tampering
157 // Log an error, throw an exception, etc.
158 }