|
1 | 1 | <?php
|
| 2 | + |
| 3 | +use Mantoufan\model\CustomerBelongsTo; |
| 4 | +use Mantoufan\model\ScopeType; |
| 5 | +use Mantoufan\model\TerminalType; |
| 6 | +use Mantoufan\tool\IdTool; |
2 | 7 | require 'common.php';
|
3 | 8 | $alipayGlobal = new Mantoufan\AliPayGlobal(array(
|
4 | 9 | 'client_id' => 'SANDBOX_5Y3A2N2YEB3002022',
|
|
7 | 12 | 'alipayPublicKey' => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAihzSL26iayp+mj1ipXa7zdQoNDPhTBaxwJ08KZn3ja+G1eFJP445AmbZwGtASGJtbnctuav+ztElJvEU+NvNW3db+EvJXsb9QIj1Elgnt5WCvMDIhUQyDcp/b7WMRZlAyAWbO52sgA9ioAwaNS/jBPtb+8lx0s0bloAVleG7st8Wy7VTXrhOgpMZqsbQfE6dM4PiX7oeU+8NWGWR+pihLYTUsjaY2l+McusfQkBqKvp1bILljbVxBtT66dldCoEPxoCUN4kihwovXhkUzDbVhKFQ8fwrwOTWi2UgNnnMNrtH+cPcJCMz3WMcUaFy0cbQlyQmUbapI3moyPx20m+7jwIDAQAB',
|
8 | 13 | 'is_sandbox' => true,
|
9 | 14 | ));
|
| 15 | +$currentUrl = getCurrentUrl(); |
10 | 16 | $type = $_GET['type'] ?? '';
|
11 |
| -route($type === 'cashier', function () use (&$alipayGlobal) { |
| 17 | +route($type === 'pay/cashier', function () use (&$alipayGlobal) { |
12 | 18 | try {
|
13 |
| - $currentUrl = getCurrentUrl(); |
14 |
| - $result = $alipayGlobal->cashier(array( |
| 19 | + $result = $alipayGlobal->payCashier(array( |
| 20 | + 'customer_belongs_to' => CustomerBelongsTo::ALIPAY_CN, // * |
15 | 21 | 'notify_url' => setQueryParams($currentUrl, array('type' => 'notify')),
|
16 | 22 | 'return_url' => setQueryParams($currentUrl, array('type' => 'return')),
|
17 | 23 | 'amount' => array(
|
|
28 | 34 | ),
|
29 | 35 | ),
|
30 | 36 | 'payment_request_id' => null,
|
| 37 | + 'settlement_strategy' => array( |
| 38 | + 'currency' => 'USD', |
| 39 | + ), |
| 40 | + 'terminal_type' => TerminalType::WEB, // * |
| 41 | + 'os_type' => null, |
31 | 42 | ));
|
32 | 43 | header('Location: ' . $result->normalUrl);
|
33 | 44 | } catch (Exception $e) {
|
34 | 45 | echo $e->getMessage();
|
35 | 46 | }
|
36 | 47 | });
|
37 | 48 |
|
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) { |
39 | 67 | try {
|
40 |
| - $currentUrl = getCurrentUrl(); |
41 |
| - $result = $alipayGlobal->agreement(array( |
| 68 | + $result = $alipayGlobal->payAgreement(array( |
| 69 | + 'customer_belongs_to' => CustomerBelongsTo::ALIPAY_CN, // * |
42 | 70 | 'notify_url' => setQueryParams($currentUrl, array('type' => 'notify')),
|
43 | 71 | 'return_url' => setQueryParams($currentUrl, array('type' => 'return')),
|
44 | 72 | 'amount' => array(
|
|
54 | 82 | ),
|
55 | 83 | ),
|
56 | 84 | ),
|
| 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 | + ), |
57 | 114 | 'payment_request_id' => null,
|
| 115 | + 'settlement_strategy' => array( |
| 116 | + 'currency' => 'USD', |
| 117 | + ), |
| 118 | + 'terminal_type' => TerminalType::WEB, // * |
| 119 | + 'os_type' => null, |
58 | 120 | ));
|
| 121 | + var_dump($result); |
59 | 122 | header('Location: ' . $result->normalUrl);
|
60 | 123 | } catch (Exception $e) {
|
61 | 124 | echo $e->getMessage();
|
|
69 | 132 |
|
70 | 133 | $alipayGlobal->sendNotifyResponseWithRSA();
|
71 | 134 | } catch (Exception $e) {
|
72 |
| - echo $e->getMesssage(); |
| 135 | + echo $e->getMessage(); |
73 | 136 | }
|
74 | 137 | });
|
75 | 138 |
|
|
0 commit comments