Skip to content

Commit 4d5a6ee

Browse files
committed
🆕update auth consult
1 parent ccf0856 commit 4d5a6ee

9 files changed

+277
-55
lines changed

example/common.php

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22
require '../vendor/autoload.php';
3+
require 'data/token.php';
34
function route(bool $boolean, callable $callback)
45
{
56
if ($boolean) {

example/data/token.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
$token = array(
3+
'access_token' => '',
4+
'access_token_expiry_time' => '',
5+
'refresh_token' => '',
6+
'refresh_token_expiry_time' => '',
7+
);

example/checkout.php example/index.php

+70-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<?php
2+
3+
use Mantoufan\model\CustomerBelongsTo;
4+
use Mantoufan\model\ScopeType;
5+
use Mantoufan\model\TerminalType;
6+
use Mantoufan\tool\IdTool;
27
require 'common.php';
38
$alipayGlobal = new Mantoufan\AliPayGlobal(array(
49
'client_id' => 'SANDBOX_5Y3A2N2YEB3002022',
@@ -7,11 +12,12 @@
712
'alipayPublicKey' => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAihzSL26iayp+mj1ipXa7zdQoNDPhTBaxwJ08KZn3ja+G1eFJP445AmbZwGtASGJtbnctuav+ztElJvEU+NvNW3db+EvJXsb9QIj1Elgnt5WCvMDIhUQyDcp/b7WMRZlAyAWbO52sgA9ioAwaNS/jBPtb+8lx0s0bloAVleG7st8Wy7VTXrhOgpMZqsbQfE6dM4PiX7oeU+8NWGWR+pihLYTUsjaY2l+McusfQkBqKvp1bILljbVxBtT66dldCoEPxoCUN4kihwovXhkUzDbVhKFQ8fwrwOTWi2UgNnnMNrtH+cPcJCMz3WMcUaFy0cbQlyQmUbapI3moyPx20m+7jwIDAQAB',
813
'is_sandbox' => true,
914
));
15+
$currentUrl = getCurrentUrl();
1016
$type = $_GET['type'] ?? '';
11-
route($type === 'cashier', function () use (&$alipayGlobal) {
17+
route($type === 'pay/cashier', function () use (&$alipayGlobal) {
1218
try {
13-
$currentUrl = getCurrentUrl();
14-
$result = $alipayGlobal->cashier(array(
19+
$result = $alipayGlobal->payCashier(array(
20+
'customer_belongs_to' => CustomerBelongsTo::ALIPAY_CN, // *
1521
'notify_url' => setQueryParams($currentUrl, array('type' => 'notify')),
1622
'return_url' => setQueryParams($currentUrl, array('type' => 'return')),
1723
'amount' => array(
@@ -28,17 +34,39 @@
2834
),
2935
),
3036
'payment_request_id' => null,
37+
'settlement_strategy' => array(
38+
'currency' => 'USD',
39+
),
40+
'terminal_type' => TerminalType::WEB, // *
41+
'os_type' => null,
3142
));
3243
header('Location: ' . $result->normalUrl);
3344
} catch (Exception $e) {
3445
echo $e->getMessage();
3546
}
3647
});
3748

38-
route($type === 'agreement', function () use (&$alipayGlobal) {
49+
route($type === 'auth/consult', function () use (&$alipayGlobal) {
50+
$auth_state = IdTool::CreateAuthState();
51+
$result = $alipayGlobal->authConsult(array(
52+
'customer_belongs_to' => CustomerBelongsTo::ALIPAY_CN, // *
53+
'auth_client_id' => null,
54+
'auth_redirect_url' => setQueryParams($currentUrl, array('type' => 'auth/apply_token/auth_code')), // *
55+
'scopes' => ScopeType::AGREEMENT_PAY, // *
56+
'auth_state' => $auth_state, // *
57+
'terminal_type' => TerminalType::WEB, // *
58+
'os_type' => null,
59+
));
60+
});
61+
62+
route($type === 'auth/apply_token/auth_code', function () use (&$alipayGlobal) {
63+
64+
});
65+
66+
route($type === 'pay/agreement', function () use (&$alipayGlobal) {
3967
try {
40-
$currentUrl = getCurrentUrl();
41-
$result = $alipayGlobal->agreement(array(
68+
$result = $alipayGlobal->payAgreement(array(
69+
'customer_belongs_to' => CustomerBelongsTo::ALIPAY_CN, // *
4270
'notify_url' => setQueryParams($currentUrl, array('type' => 'notify')),
4371
'return_url' => setQueryParams($currentUrl, array('type' => 'return')),
4472
'amount' => array(
@@ -54,8 +82,43 @@
5482
),
5583
),
5684
),
85+
'goods' => array(
86+
array(
87+
'id' => null,
88+
'name' => 'Goods Name',
89+
'category' => null,
90+
'brand' => null,
91+
'unit_amount' => null,
92+
'quantity' => null,
93+
'sku_name' => null,
94+
),
95+
),
96+
'merchant' => array(
97+
'MCC' => null,
98+
'name' => null,
99+
'display_name' => null,
100+
'address' => null,
101+
'register_date' => null,
102+
'store' => null,
103+
'type' => null,
104+
),
105+
'buyer' => array(
106+
'id' => null,
107+
'name' => array(
108+
'first_name' => null,
109+
'last_name' => null,
110+
),
111+
'phone_no' => null,
112+
'email' => null,
113+
),
57114
'payment_request_id' => null,
115+
'settlement_strategy' => array(
116+
'currency' => 'USD',
117+
),
118+
'terminal_type' => TerminalType::WEB, // *
119+
'os_type' => null,
58120
));
121+
var_dump($result);
59122
header('Location: ' . $result->normalUrl);
60123
} catch (Exception $e) {
61124
echo $e->getMessage();
@@ -69,7 +132,7 @@
69132

70133
$alipayGlobal->sendNotifyResponseWithRSA();
71134
} catch (Exception $e) {
72-
echo $e->getMesssage();
135+
echo $e->getMessage();
73136
}
74137
});
75138

0 commit comments

Comments
 (0)