Skip to content

Commit e61cc3b

Browse files
committed
update example add namespace
1 parent f7e816b commit e61cc3b

File tree

3 files changed

+89
-43
lines changed

3 files changed

+89
-43
lines changed

README.md

Lines changed: 81 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,93 @@ PHP version:5.4.7+
44
Copyright:Ant financial services group
55
```
66

7+
### Composer
8+
9+
You can install the bindings via [Composer](http://getcomposer.org/). Run the following command:
10+
11+
```bash
12+
composer require antom/global-open-sdk-php
13+
```
14+
15+
To use the bindings, use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading):
16+
17+
```php
18+
require_once 'vendor/autoload.php';
19+
```
20+
21+
### Manual Installation
22+
23+
If you do not wish to use Composer, you can download the [latest release](https://github.com/alipay/global-open-sdk-php/releases). Then, to use the bindings, include the `init.php` file.
24+
25+
```php
26+
require_once '/path/to/global-open-sdk-php/init.php';
27+
```
28+
29+
730
#### 1 Important note
831
The SDK mainly shows how to access the alipay gateway, which cannot guarantee the performance and stability.
932

1033
#### 2 The demo code for create order
1134
```
12-
$alipayCreateOrderRequest = new AlipayCreateOrderRequest();
13-
14-
$clientId = "your clientId";
15-
$path = "/ams/sandbox/api/v1/payments/create";
16-
17-
$productCode = ProductCodeType::CASHIER_PAYMENT;
18-
$paymentRequestId = "demo-test-id";
19-
$order = new Order();
20-
$order->setOrderDescription("test order desc");
21-
$order->setReferenceOrderId("102775745075669");
22-
$orderAmount = new Amount();
23-
$orderAmount->setCurrency("USD");
24-
$orderAmount->setValue("100");
25-
$order->setOrderAmount($orderAmount);
26-
27-
$paymentAmount = new Amount();
28-
$paymentAmount->setCurrency("USD");
29-
$paymentAmount->setValue("100");
30-
$paymentNotifyUrl = "https://www.alipay.com/notify";
31-
$paymentRedirectUrl = "https://www.alipay.com";
32-
33-
$alipayCreateOrderRequest->setClientId($clientId);
34-
$alipayCreateOrderRequest->setPath($path);
35-
$alipayCreateOrderRequest->setProductCode($productCode);
36-
$alipayCreateOrderRequest->setPaymentRequestId($paymentRequestId);
37-
$alipayCreateOrderRequest->setPaymentAmount($paymentAmount);
38-
$alipayCreateOrderRequest->setOrder($order);
39-
$alipayCreateOrderRequest->setPaymentNotifyUrl($paymentNotifyUrl);
40-
$alipayCreateOrderRequest->setPaymentRedirectUrl($paymentRedirectUrl);
41-
42-
$merchantPrivateKey = "your privateKey";
43-
$alipayPublicKey = "your alipayPublicKey";
44-
45-
$alipayClient = new DefaultAlipayClient("https://open-sea.alipay.com", $merchantPrivateKey, $alipayPublicKey);
46-
$alipayResponse = $alipayClient->execute($alipayCreateOrderRequest);
35+
$request = new AlipayPayRequest();
36+
$paymentRequestId = 'PR_' . round(microtime(true) * 1000);
37+
$order = new Order();
38+
$order->setOrderDescription("test order desc");
39+
$order->setReferenceOrderId("102775745075668");
40+
$orderAmount = new Amount();
41+
$orderAmount->setCurrency("HKD");
42+
$orderAmount->setValue("100");
43+
$order->setOrderAmount($orderAmount);
44+
45+
$merchant = new Merchant();
46+
$merchant->setReferenceMerchantId('seller2322174590001');
47+
$merchant->setMerchantMCC('7011');
48+
$merchant->setMerchantName('Some_Mer');
49+
50+
$store = new Store();
51+
$store->setStoreMCC('7011');
52+
$store->setReferenceStoreId('store232217459000021');
53+
$store->setStoreName('Some_Store');
54+
55+
$merchant->setStore($store);
56+
57+
$order->setMerchant($merchant);
58+
59+
$env = new Env();
60+
$env->setUserAgent('"Mozilla/5.0 (iPhone; CPU iPhone OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15G77 NebulaSDK/1.8.100112 Nebula PSDType(1) AlipayDefined(nt:4G,ws:320|504|2.0) AliApp(AP/10.1.32.600) AlipayClient/10.1.32.600 Alipay Language/zh-Hans AlipayConnect"');
61+
$env->setOsType(OsType::ANDROID);
62+
$env->setTerminalType(TerminalType::WEB);
63+
$order->setEnv($env);
64+
65+
$request->setOrder($order);
66+
67+
$paymentAmount = new Amount();
68+
$paymentAmount->setCurrency("HKD");
69+
$paymentAmount->setValue("100");
70+
$request->setPaymentAmount($paymentAmount);
71+
72+
$paymentNotifyUrl = "https://www.alipay.com/notify";
73+
$paymentRedirectUrl = "https://www.alipay.com";
74+
75+
$request->setPaymentNotifyUrl($paymentNotifyUrl);
76+
$request->setPaymentRedirectUrl($paymentRedirectUrl);
77+
78+
$paymentMethod = new PaymentMethod();
79+
$paymentMethod->setPaymentMethodType(WalletPaymentMethodType::ALIPAY_HK);
80+
$request->setPaymentMethod($paymentMethod);
81+
82+
$request->setProductCode(ProductCodeType::CASHIER_PAYMENT);
83+
84+
$request->setClientId(clientId);
85+
86+
$request->setPaymentRequestId($paymentRequestId);
87+
88+
$settlementStrategy = new SettlementStrategy();
89+
$settlementStrategy->setSettlementCurrency("USD");
90+
$request->setSettlementStrategy($settlementStrategy);
4791
92+
$alipayClient = new DefaultAlipayClient("https://open-sea-global.alipay.com", merchantPrivateKey, alipayPublicKey);
93+
$alipayResponse = $alipayClient->execute($request);
4894
```
4995

5096
The execute method contains the HTTP request to the gateway.

example/CustomsTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313

1414

15-
const clientId = "SANDBOX_5YBZ1G2ZHUPS06086";
16-
const merchantPrivateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDvd0h55/WfbUrXfBkc0+X3H5RpD0b0T4yEVwnqUcFea7epULNstd5ItZXkV5UdkRiOqwUXGqTw2jLFbo/Qdgss+yXiUiIvB2ynncBNWNw9pCuzS+GUMw4ZARSwASPbb5hB0iK3ASl7BXOEncRuybm4gn3tD975hCGHpMeSTx0Z8rCHBqaterpyCPs68Op5kzoTYHiMCGozLeMUEand1O6OPZNQxM5c+ME+YaA6g4VbN6CjtxEihU/lhpruGN5yD+/zBRSdqrD0qxIyq3bxhTYzIXjImR4FBfqz5CoSwu7jFZdxTMyIW4lr/dXzqIvCcjrDP4R8aRB4Dy81vPTP0vnfAgMBAAECggEAIBW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jtiEFTsyuyjKSvYNrhCJcgzNiGQSs55k1LEWuxNzvNuHaT3djcLINz9WrzZkShJBUZO50cTUcCjqw1C9fBGiqU7zQBvCb3rdNzAZwmEqjjjrT1dYH4gGdYc1dSc6XHwWWbduqbT91DaENxd4wIuY=";
17-
const alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkJIL3C7NSzSQxP1DNK0Grktr5G5bMEj4ndEIBnSyFv8+e6ytS+G1+ch7EdZ4Lt7KYUGoFW1wJKyTS8V5UBMJTWxAkdc2uX3GrQiWbPvReMl3sNa3SC9Kmi8ofVKQdpAt8aZZaTLxmti0YyCh8zUTddE9AOeMZi8xvzC8chcGbfx4FA5meFGkPEBeYfxZgQzCjXnMJ/A2JFeh5g2443pfAq/caoIamcnTcA9qhJCMaqDyXb2pxXmg/VOClhqhaOjj4dnxzYKln1YNJw02SaVT9zjkNJkbY2QzCjEV0NdG/QLCQ/xBkFlDvlJ+nyCiTySqVOuJXGCos1cljMoYJGZLXQIDAQAB";
18-
const gatewayUrl = "https://open-sea-global.alipay.com";
15+
const clientId = "";
16+
const merchantPrivateKey = "";
17+
const alipayPublicKey = "";
18+
const gatewayUrl = "";
1919

2020

2121
function declares($paymentId)

example/PayTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626

2727

2828

29-
const clientId = "SANDBOX_5YBZ1G2ZHUPS06086";
30-
const merchantPrivateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDvd0h55/WfbUrXfBkc0+X3H5RpD0b0T4yEVwnqUcFea7epULNstd5ItZXkV5UdkRiOqwUXGqTw2jLFbo/Qdgss+yXiUiIvB2ynncBNWNw9pCuzS+GUMw4ZARSwASPbb5hB0iK3ASl7BXOEncRuybm4gn3tD975hCGHpMeSTx0Z8rCHBqaterpyCPs68Op5kzoTYHiMCGozLeMUEand1O6OPZNQxM5c+ME+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IQmmoXQ6F1kN3mRqciRe8RFZj9q1ollGMk1y6/HQA9SePlV8cwQmeKodJp3glLnC4PtXso64S+WBeo5YG0YFms02oZZFObpyQbePcDGzXc8naSndsCgYEAu35IqER+dxQNQxrgT83lzYDjtiEFTsyuyjKSvYNrhCJcgzNiGQSs55k1LEWuxNzvNuHaT3djcLINz9WrzZkShJBUZO50cTUcCjqw1C9fBGiqU7zQBvCb3rdNzAZwmEqjjjrT1dYH4gGdYc1dSc6XHwWWbduqbT91DaENxd4wIuY=";
31-
const alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkJIL3C7NSzSQxP1DNK0Grktr5G5bMEj4ndEIBnSyFv8+e6ytS+G1+ch7EdZ4Lt7KYUGoFW1wJKyTS8V5UBMJTWxAkdc2uX3GrQiWbPvReMl3sNa3SC9Kmi8ofVKQdpAt8aZZaTLxmti0YyCh8zUTddE9AOeMZi8xvzC8chcGbfx4FA5meFGkPEBeYfxZgQzCjXnMJ/A2JFeh5g2443pfAq/caoIamcnTcA9qhJCMaqDyXb2pxXmg/VOClhqhaOjj4dnxzYKln1YNJw02SaVT9zjkNJkbY2QzCjEV0NdG/QLCQ/xBkFlDvlJ+nyCiTySqVOuJXGCos1cljMoYJGZLXQIDAQAB";
32-
const gatewayUrl = "https://open-sea-global.alipay.com";
29+
const clientId = "";
30+
const merchantPrivateKey = "";
31+
const alipayPublicKey = "";
32+
const gatewayUrl = "";
3333

3434

3535
function pay()

0 commit comments

Comments
 (0)