Skip to content

Commit

Permalink
新增金流&境外物流SDK
Browse files Browse the repository at this point in the history
#76500
  • Loading branch information
adelachang0418 committed Dec 23, 2020
0 parents commit 6845057
Show file tree
Hide file tree
Showing 61 changed files with 2,401 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 綠界科技全方位金流 SDK
* 綠界科技對於有收款需求的會員,提供完整的交易介接API,並有多種收款方式(All In One)可選擇使用。
本套件為PHP版,可使用作建立訂單,接受付款通知,查詢訂單等金流交易的應用。
* 收款方式清單:
* 信用卡(一次付清、分期付款、定期定額)
* 網路ATM
* ATM櫃員機
* 超商代碼
* 超商條碼

# 目錄
* [環境需求](#環境需求)
* [安裝方式](#安裝方式)
* [文件與協助](#文件與協助)

# 環境需求
- [PHP](https://www.php.net/) 5.6 以上

# 安裝方式
建議使用 [Composer](https://getcomposer.org/) 安裝
```bash
composer require ecpay/sdk
```

# 文件與協助
- [串接文件](https://www.ecpay.com.tw/Service/API_Dwnld)
- [綠界技術服務工程師信箱](mailto:[email protected])
- [範例](example)
17 changes: 17 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "ecpay/sdk",
"description": "ECPay SDK",
"type": "library",
"require": {
"php": ">=5.3"
},
"license": "MIT",
"require-dev": {
"phpunit/phpunit": "*"
},
"autoload": {
"psr-4": {
"Ecpay\\Sdk\\": "src/"
}
}
}
34 changes: 34 additions & 0 deletions example/Logistics/CrossBorder/CreateTestData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Ecpay\Sdk\Factories\Factory;
use Ecpay\Sdk\Exceptions\RtnException;

require __DIR__ . '/../../../vendor/autoload.php';

try {
$factory = new Factory;
$hashKey = '5294y06JbISpM5x9';
$hashIv = 'v77hoKGq4kWxNNIS';
$postService = $factory->createWithHash('PostWithAesJsonResponseService', $hashKey, $hashIv);

$data = [
'MerchantID' => '2000132',
'Country' => 'SG',
'LogisticsType' => 'CB',
'LogisticsSubType' => 'UNIMARTCBCVS',
];
$input = [
'MerchantID' => '2000132',
'RqHeader' => [
'Timestamp' => time(),
'Revision' => '1.0.0',
],
'Data' => $data,
];
$url = 'https://logistics-stage.ecpay.com.tw/CrossBorder/CreateTestData';

$response = $postService->post($input, $url);
var_dump($response);
} catch (RtnException $e) {
echo '(' . $e->getCode() . ')' . $e->getMessage() . PHP_EOL;
}
51 changes: 51 additions & 0 deletions example/Logistics/CrossBorder/CreateUnimartCvsOrder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

use Ecpay\Sdk\Factories\Factory;
use Ecpay\Sdk\Exceptions\RtnException;

require __DIR__ . '/../../../vendor/autoload.php';

try {
$factory = new Factory;
$hashKey = '5294y06JbISpM5x9';
$hashIv = 'v77hoKGq4kWxNNIS';
$postService = $factory->createWithHash('PostWithAesJsonResponseService', $hashKey, $hashIv);

$data = [
'MerchantID' => '2000132',
'MerchantTradeDate' => date('Y/m/d H:i:s'),
'MerchantTradeNo' => 'Test' . time(),
'LogisticsType' => 'CB',
'LogisticsSubType' => 'UNIMARTCBCVS',
'GoodsAmount' => 1000,
'GoodsWeight' => 5.0,
'GoodsEnglishName' => 'Test goods',
'ReceiverCountry' => 'SG',
'ReceiverName' => 'Test Receiver',
'ReceiverCellPhone' => '65212345678',
'ReceiverStoreID' => '711_1',
'ReceiverZipCode' => '419701',
'ReceiverAddress' => 'address 23424 -fr 13-2',
'ReceiverEmail' => '[email protected]',
'SenderName' => 'Test Sender',
'SenderCellPhone' => '886987654321',
'SenderAddress' => 'address 23424 -fr 13-2, Nangang Dist., Taipei City 115, Taiwan (R.O.C.)',
'SenderEmail' => '[email protected]',
'Remark' => 'Test Remark',
'ServerReplyURL' => 'https://logistics-stage.ecpay.com.tw/MockMerchant/NoticsTestRtn',
];
$input = [
'MerchantID' => '2000132',
'RqHeader' => [
'Timestamp' => time(),
'Revision' => '1.0.0',
],
'Data' => $data,
];
$url = 'https://logistics-stage.ecpay.com.tw/CrossBorder/Create';

$response = $postService->post($input, $url);
var_dump($response);
} catch (RtnException $e) {
echo '(' . $e->getCode() . ')' . $e->getMessage() . PHP_EOL;
}
50 changes: 50 additions & 0 deletions example/Logistics/CrossBorder/CreateUnimartHomeOrder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

use Ecpay\Sdk\Factories\Factory;
use Ecpay\Sdk\Exceptions\RtnException;

require __DIR__ . '/../../../vendor/autoload.php';

try {
$factory = new Factory;
$hashKey = '5294y06JbISpM5x9';
$hashIv = 'v77hoKGq4kWxNNIS';
$postService = $factory->createWithHash('PostWithAesJsonResponseService', $hashKey, $hashIv);

$data = [
'MerchantID' => '2000132',
'MerchantTradeDate' => date('Y/m/d H:i:s'),
'MerchantTradeNo' => 'Test' . time(),
'LogisticsType' => 'CB',
'LogisticsSubType' => 'UNIMARTCBHOME',
'GoodsAmount' => 1000,
'GoodsWeight' => 5.0,
'GoodsEnglishName' => 'Test goods',
'ReceiverCountry' => 'SG',
'ReceiverName' => 'Test Receiver',
'ReceiverCellPhone' => '65212345678',
'ReceiverZipCode' => '419701',
'ReceiverAddress' => 'address 23424 -fr 13-2',
'ReceiverEmail' => '[email protected]',
'SenderName' => 'Test Sender',
'SenderCellPhone' => '886987654321',
'SenderAddress' => 'address 23424 -fr 13-2, Nangang Dist., Taipei City 115, Taiwan (R.O.C.)',
'SenderEmail' => '[email protected]',
'Remark' => 'Test Remark',
'ServerReplyURL' => 'https://logistics-stage.ecpay.com.tw/MockMerchant/NoticsTestRtn',
];
$input = [
'MerchantID' => '2000132',
'RqHeader' => [
'Timestamp' => time(),
'Revision' => '1.0.0',
],
'Data' => $data,
];
$url = 'https://logistics-stage.ecpay.com.tw/CrossBorder/Create';

$response = $postService->post($input, $url);
var_dump($response);
} catch (RtnException $e) {
echo '(' . $e->getCode() . ')' . $e->getMessage() . PHP_EOL;
}
16 changes: 16 additions & 0 deletions example/Logistics/CrossBorder/GetMapResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use Ecpay\Sdk\Factories\Factory;
use Ecpay\Sdk\Response\ArrayResponse;
use Ecpay\Sdk\Exceptions\RtnException;

require __DIR__ . '/../../../vendor/autoload.php';

try {
$factory = new Factory;
$arrayResponse = $factory->create(ArrayResponse::class);

var_dump($arrayResponse->get($_POST));
} catch (RtnException $e) {
echo '(' . $e->getCode() . ')' . $e->getMessage() . PHP_EOL;
}
42 changes: 42 additions & 0 deletions example/Logistics/CrossBorder/GetStatusChangedResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

use Ecpay\Sdk\Factories\Factory;
use Ecpay\Sdk\Exceptions\RtnException;
use Ecpay\Sdk\Request\AesRequest;
use Ecpay\Sdk\Response\AesJsonResponse;

require __DIR__ . '/../../../vendor/autoload.php';

try {
$factory = new Factory;
$hashKey = '5294y06JbISpM5x9';
$hashIv = 'v77hoKGq4kWxNNIS';
$jsonRequest = $factory->createWithHash(AesJsonResponse::class, $hashKey, $hashIv);
$aesJsonResponse = $factory->createWithHash(AesRequest::class, $hashKey, $hashIv);

$json = file_get_contents('php://input');

$request = $jsonRequest->get($json);

/**
* 廠商端變更物流狀態(貨態)流程
* Ex: 變更物流狀態 > ...
* 以下為變更成功回應參考範例
*/
$data = [
'RtnCode' => 1,
'RtnMsg' => 'OK',
];
$output = [
'MerchantID' => '2000132',
'RqHeader' => [
'Timestamp' => time(),
],
'TransCode' => 1,
'TransMsg' => '',
'Data' => $data,
];
echo $aesJsonResponse->get($output);
} catch (RtnException $e) {
echo '(' . $e->getCode() . ')' . $e->getMessage() . PHP_EOL;
}
27 changes: 27 additions & 0 deletions example/Logistics/CrossBorder/Map.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Ecpay\Sdk\Factories\Factory;
use Ecpay\Sdk\Exceptions\RtnException;

require __DIR__ . '/../../../vendor/autoload.php';

try {
$factory = new Factory;
$hashKey = '5294y06JbISpM5x9';
$hashIv = 'v77hoKGq4kWxNNIS';
$postService = $factory->createWithHash('AutoSubmitFormWithAesService', $hashKey, $hashIv);

$input = [
'MerchantID' => '2000132',
'MerchantTradeNo' => 'Test' . time(),
'LogisticsType' => 'CB',
'LogisticsSubType' => 'UNIMARTCBCVS',
'Destination' => 'SG',
'ServerReplyURL' => 'https://logistics-stage.ecpay.com.tw/MockMerchant/NoticsTestRtn',
];
$action = 'https://logistics-stage.ecpay.com.tw/CrossBorder/Map';

echo $postService->generate($input, $action);
} catch (RtnException $e) {
echo '(' . $e->getCode() . ')' . $e->getMessage() . PHP_EOL;
}
32 changes: 32 additions & 0 deletions example/Logistics/CrossBorder/Print.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Ecpay\Sdk\Factories\Factory;
use Ecpay\Sdk\Exceptions\RtnException;

require __DIR__ . '/../../../vendor/autoload.php';

try {
$factory = new Factory;
$hashKey = '5294y06JbISpM5x9';
$hashIv = 'v77hoKGq4kWxNNIS';
$postService = $factory->createWithHash('PostWithAesJsonResponseService', $hashKey, $hashIv);

$data = [
'MerchantID' => '2000132',
'LogisticsID' => '1658389',
];
$input = [
'MerchantID' => '2000132',
'RqHeader' => [
'Timestamp' => time(),
'Revision' => '1.0.0',
],
'Data' => $data,
];
$url = 'https://logistics-stage.ecpay.com.tw/CrossBorder/Print';

$response = $postService->post($input, $url);
var_dump($response);
} catch (RtnException $e) {
echo '(' . $e->getCode() . ')' . $e->getMessage() . PHP_EOL;
}
32 changes: 32 additions & 0 deletions example/Logistics/CrossBorder/QueryLogisticsTradeInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Ecpay\Sdk\Factories\Factory;
use Ecpay\Sdk\Exceptions\RtnException;

require __DIR__ . '/../../../vendor/autoload.php';

try {
$factory = new Factory;
$hashKey = '5294y06JbISpM5x9';
$hashIv = 'v77hoKGq4kWxNNIS';
$postService = $factory->createWithHash('PostWithAesJsonResponseService', $hashKey, $hashIv);

$data = [
'MerchantID' => '2000132',
'LogisticsID' => '1658389',
];
$input = [
'MerchantID' => '2000132',
'RqHeader' => [
'Timestamp' => time(),
'Revision' => '1.0.0',
],
'Data' => $data,
];
$url = 'https://logistics-stage.ecpay.com.tw/CrossBorder/QueryLogisticsTradeInfo';

$response = $postService->post($input, $url);
var_dump($response);
} catch (RtnException $e) {
echo '(' . $e->getCode() . ')' . $e->getMessage() . PHP_EOL;
}
27 changes: 27 additions & 0 deletions example/Payment/Capture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Ecpay\Sdk\Factories\Factory;
use Ecpay\Sdk\Exceptions\RtnException;

require __DIR__ . '/../../vendor/autoload.php';

try {
$factory = new Factory;
$hashKey = '5294y06JbISpM5x9';
$hashIv = 'v77hoKGq4kWxNNIS';
$postService = $factory->createWithHash('PostWithCmvEncodedStrResponseService', $hashKey, $hashIv);

$input = [
'MerchantID' => '2000132',
'MerchantTradeNo' => '5fa271cc74e51',
'TradeNo' => '2011041718071855',
'Action' => 'C',
'TotalAmount' => 8685,
];
$url = 'https://payment-stage.ecpay.com.tw/CreditDetail/DoAction';

$response = $postService->post($input, $url);
var_dump($response);
} catch (RtnException $e) {
echo '(' . $e->getCode() . ')' . $e->getMessage() . PHP_EOL;
}
Loading

0 comments on commit 6845057

Please sign in to comment.