-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.php
More file actions
105 lines (89 loc) · 3.34 KB
/
handler.php
File metadata and controls
105 lines (89 loc) · 3.34 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
99
100
101
102
103
104
105
<?php
/**
* S-PayWay Client - API Examples
*
* This demonstrates the 3 core API actions:
* 1. payment_method - Get available payment methods
* 2. status - Check invoice payment status
* 3. checkout - Create payment session
*/
require_once './src/S_PayWayClient.php';
// Configuration
$accessToken = 'SAT_7dc7dda106a0c6bf9a83e01e-ccbc726e72d11380d96eb591-31d93122a7591760110814'; // Replace your Access Token, you can find it in the settings of S-PayWay merchant panel.
$client = new S_PayWayClient($accessToken);
function getPaymentMethods() {
global $client;
try {
return $client->getPaymentMethods();
} catch (Exception $e) {
echo "Error: {$e->getMessage()}<br>";
return [];
}
}
function checkInvoiceStatus($invoiceToken) {
global $client;
try {
$result = $client->getInvoiceStatus($invoiceToken);
$invoice = $result['data'];
echo "<br>Invoice Details:<br>";
echo " ID: {$invoice['id']}<br>";
echo " Status: {$invoice['status']}<br>";
echo " Amount: \${$invoice['total']}<br>";
echo " Customer: {$invoice['customer']['full_name']}<br>";
echo " Product: {$invoice['goods']['name']}<br>";
return $invoice;
} catch (Exception $e) {
echo "Error: {$e->getMessage()}<br>";
return null;
}
}
function createCheckout($invoiceToken, $paymentMethod) {
global $client;
try {
$requestId = S_PayWayClient::generateRequestId();
$result = $client->checkout($invoiceToken, $paymentMethod, $requestId);
$payment = $result['data'];
echo "<br>Payment Information:<br>";
echo " Method: {$payment['payment_method']}<br>";
echo " Amount: \${$payment['amount']}<br>";
echo " Fee: \${$payment['processingFee']}<br>";
echo " Receiver: {$payment['receiver_name']}<br>";
echo " Remark: {$payment['remark_code']}<br>";
echo '<img src="' . $payment['qrcode_base64'] . '">';
return $payment;
} catch (Exception $e) {
echo "Error: {$e->getMessage()}<br>";
return null;
}
}
function completePaymentFlow($invoiceToken) {
echo "=== S-PayWay Payment Flow ===<br><br>";
echo "Step 1: Getting payment methods...<br>";
$methods = getPaymentMethods();
if (empty($methods)) {
echo "No payment methods available!<br>";
return;
}
echo "<br>Step 2: Checking invoice status...<br>";
$invoice = checkInvoiceStatus($invoiceToken);
if (!$invoice) {
echo "Invoice not found!<br>";
return;
}
if ($invoice['status'] === 'Paid') {
echo "<br>✓ Invoice already paid!<br>";
return;
}
echo "<br>Step 3: Creating checkout...<br>";
$selectedMethod = 'binance_c2c_usdt';
$payment = createCheckout($invoiceToken, $selectedMethod);
if ($payment) {
echo "<br>✓ Payment session created successfully!<br>";
}
}
echo "╔═════════════════╗<br>";
echo "║ S-PayWay Client - Examples ║<br>";
echo "╚═════════════════╝<br><br>";
// Run example
$invoiceToken = 'fc22ccf6-2ed2-412a-80ff-d0fbb5f1684d'; // Replace with your own invoice token. Invoice tokens from other merchants are not supported.
completePaymentFlow($invoiceToken);