Skip to content

Commit 6ad6976

Browse files
authored
Merge pull request #12 from alipay/feature-update-composer
update add namespace
2 parents 1b3c306 + 062e67f commit 6ad6976

File tree

120 files changed

+5836
-5277
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+5836
-5277
lines changed

BaseAlipayClient.php

Lines changed: 0 additions & 180 deletions
This file was deleted.

README.md

Lines changed: 85 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,96 @@ 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
24+
the [latest release](https://github.com/alipay/global-open-sdk-php/releases). Then, to use the bindings, include the
25+
`init.php` file.
26+
27+
```php
28+
require_once '/path/to/global-open-sdk-php/init.php';
29+
```
30+
731
#### 1 Important note
32+
833
The SDK mainly shows how to access the alipay gateway, which cannot guarantee the performance and stability.
934

1035
#### 2 The demo code for create order
36+
1137
```
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);
38+
$request = new AlipayPayRequest();
39+
$paymentRequestId = 'PR_' . round(microtime(true) * 1000);
40+
$order = new Order();
41+
$order->setOrderDescription("test order desc");
42+
$order->setReferenceOrderId("102775745075668");
43+
$orderAmount = new Amount();
44+
$orderAmount->setCurrency("HKD");
45+
$orderAmount->setValue("100");
46+
$order->setOrderAmount($orderAmount);
47+
48+
$merchant = new Merchant();
49+
$merchant->setReferenceMerchantId('seller2322174590001');
50+
$merchant->setMerchantMCC('7011');
51+
$merchant->setMerchantName('Some_Mer');
4752
53+
$store = new Store();
54+
$store->setStoreMCC('7011');
55+
$store->setReferenceStoreId('store232217459000021');
56+
$store->setStoreName('Some_Store');
57+
58+
$merchant->setStore($store);
59+
60+
$order->setMerchant($merchant);
61+
62+
$env = new Env();
63+
$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"');
64+
$env->setOsType(OsType::ANDROID);
65+
$env->setTerminalType(TerminalType::WEB);
66+
$order->setEnv($env);
67+
68+
$request->setOrder($order);
69+
70+
$paymentAmount = new Amount();
71+
$paymentAmount->setCurrency("HKD");
72+
$paymentAmount->setValue("100");
73+
$request->setPaymentAmount($paymentAmount);
74+
75+
$paymentNotifyUrl = "https://www.alipay.com/notify";
76+
$paymentRedirectUrl = "https://www.alipay.com";
77+
78+
$request->setPaymentNotifyUrl($paymentNotifyUrl);
79+
$request->setPaymentRedirectUrl($paymentRedirectUrl);
80+
81+
$paymentMethod = new PaymentMethod();
82+
$paymentMethod->setPaymentMethodType(WalletPaymentMethodType::ALIPAY_HK);
83+
$request->setPaymentMethod($paymentMethod);
84+
85+
$request->setProductCode(ProductCodeType::CASHIER_PAYMENT);
86+
87+
$request->setClientId(clientId);
88+
89+
$request->setPaymentRequestId($paymentRequestId);
90+
91+
$settlementStrategy = new SettlementStrategy();
92+
$settlementStrategy->setSettlementCurrency("USD");
93+
$request->setSettlementStrategy($settlementStrategy);
94+
95+
$alipayClient = new DefaultAlipayClient("https://open-sea-global.alipay.com", merchantPrivateKey, alipayPublicKey);
96+
$alipayResponse = $alipayClient->execute($request);
4897
```
4998

5099
The execute method contains the HTTP request to the gateway.
@@ -81,6 +130,7 @@ $alipayPayResponse = $yourAlipayClient->execute($aliPayRequest);
81130
```
82131

83132
#### 3 If you don't care about HTTP calls,the sample for sign and verify
133+
84134
```
85135
$signReqValue = SignatureTool::sign($httpMethod, $path, $clientId, $reqTime, $reqBody, $merchantPrivateKey);
86136
$isVerifyPass = SignatureTool::verify($httpMethod, $path, $clientId, $rspTime, $rspBody, $rspSignValue, $alipayPublicKey);

0 commit comments

Comments
 (0)