forked from mantoufan/alipay-global-sdk-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
358 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
require 'common.php'; | ||
$type = $_GET['type'] ?? 'request'; | ||
route($type === 'request', function () { | ||
$alipayGlobal = new Mantoufan\AliPayGlobal(array( | ||
'client_id' => 'SANDBOX_5Y3A2N2YEB3002022', | ||
'endpoint_area' => 'ASIA', | ||
'merchantPrivateKey' => 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCfsLCiwlKAiYdtLNoUTxx57SUFFrp4+qEnIn0gCl+bBj9/JiOiG24TSoFlvFAjFiTkL3udOXg9OXwtz0svXLtjrkhAQF7mmfl1Myj/5DrwZJSATO/503ILXBJuyAr64WG1xFl6KPeFfvCeZ6Yo75fIL/vbi7x/8RD7KwrSD4HCebpc+VNSb18ha7wPFDNJ2wgaNVHnPtxwYjiUW2VqBC5GkS1roAH2ernywC2oxXwaOqhxawbBBSMj6S3H73JENY7Sf0fhweKffp0qFqhc3s7lNppo1vTVO+UhVobIkFhpDp/bBddHlc7dCCzqLy65S/0cXyvYjezdkkiKv3pW4EnTAgMBAAECggEAOsRVXLBSmEcEdaMJ5mtuuVgSRZslqJvjbnl8vqvSn0RfXbV1a5TYn3TNxdjVTPQ7Q1ZOEYAyxaVAE8OzkYx40agzoqGNyyNi8ESRlAozvn/lPooRzkiIMbICfo5TrBwBT1kg7Jni7VfXyROvzGTP4LX348W66wKWEzi11LQsNprr9Yty9VHX9xHAcrMvveLYbcjnJbka/XPmoKMpiQzk+q8/7d/IeSkt32TT6cmQGmLcucM68fM859/N/7fUnG8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GJtbnctuav+ztElJvEU+NvNW3db+EvJXsb9QIj1Elgnt5WCvMDIhUQyDcp/b7WMRZlAyAWbO52sgA9ioAwaNS/jBPtb+8lx0s0bloAVleG7st8Wy7VTXrhOgpMZqsbQfE6dM4PiX7oeU+8NWGWR+pihLYTUsjaY2l+McusfQkBqKvp1bILljbVxBtT66dldCoEPxoCUN4kihwovXhkUzDbVhKFQ8fwrwOTWi2UgNnnMNrtH+cPcJCMz3WMcUaFy0cbQlyQmUbapI3moyPx20m+7jwIDAQAB', | ||
'is_sandbox' => true, | ||
)); | ||
|
||
try { | ||
$result = $alipayGlobal->checkout(array( | ||
'notify_url' => 'https://www.alipay.com/notify', | ||
'return_url' => 'https://www.alipay.com', | ||
'amount' => array( | ||
'currency' => 'USD', | ||
'value' => '1', | ||
), | ||
'order' => array( | ||
'id' => null, | ||
'desc' => 'Order Desc', | ||
'extend_info' => array( | ||
'china_extra_trans_info' => array( | ||
'business_type' => 'MEMBERSHIP', | ||
), | ||
), | ||
), | ||
'payment_request_id' => null, | ||
)); | ||
header('Location: ' . $result->normalUrl); | ||
} catch (Exception $e) { | ||
echo $e->getMessage(); | ||
} | ||
}); | ||
|
||
route($type === 'notify', function () { | ||
print_r($_SERVER); | ||
echo 'success'; | ||
}); | ||
|
||
route($type === 'return', function () { | ||
echo 'Payment completed'; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
require '../vendor/autoload.php'; | ||
function route(bool $boolean, callable $callback) | ||
{ | ||
if ($boolean) { | ||
$callback(); | ||
exit; | ||
} | ||
} | ||
|
||
function currentUrl() | ||
{ | ||
return 'http' . ($_SERVER['HTTPS'] === 'on' ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . (in_array($_SERVER['SERVER_PORT'], array(80, 443)) ? '' : ''); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
namespace Mantoufan; | ||
|
||
use Mantoufan\DefaultAlipayClient; | ||
use Mantoufan\model\Amount; | ||
use Mantoufan\model\ChinaExtraTransInfo; | ||
use Mantoufan\model\CustomerBelongsTo; | ||
use Mantoufan\model\Endpoint; | ||
use Mantoufan\model\Env; | ||
use Mantoufan\model\ExtendInfo; | ||
use Mantoufan\model\Order; | ||
use Mantoufan\model\PaymentMethod; | ||
use Mantoufan\model\ProductCodeType; | ||
use Mantoufan\model\SettlementStrategy; | ||
use Mantoufan\model\TerminalType; | ||
use Mantoufan\request\pay\AlipayPayRequest; | ||
|
||
class AliPayGlobal | ||
{ | ||
public $alipayClient; | ||
public $client_id; | ||
public $is_sandbox; | ||
public function __construct($params) | ||
{ | ||
$params = array_merge(array( | ||
'client_id' => '', | ||
'endpoint_area' => 'ASIA', | ||
'merchantPrivateKey' => '', | ||
'alipayPublicKey' => '', | ||
'is_sandbox' => false, | ||
), $params); | ||
$this->client_id = $params['client_id']; | ||
$this->is_sandbox = $params['is_sandbox']; | ||
$this->alipayClient = new DefaultAlipayClient( | ||
constant(Endpoint::class . '::' . $params['endpoint_area']), | ||
$params['merchantPrivateKey'], | ||
$params['alipayPublicKey'] | ||
); | ||
} | ||
public static function CreateOredrId() | ||
{ | ||
list($ms) = explode(' ', microtime()); | ||
return 'ORDER-' . date('YmdHis') . ($ms * 1000000) . rand(00, 99); | ||
} | ||
|
||
public static function CreatePaymentRequestId() | ||
{ | ||
list($ms) = explode(' ', microtime()); | ||
return 'PAY-' . date('YmdHis') . ($ms * 1000000) . rand(00, 99); | ||
} | ||
|
||
public function checkout($params) | ||
{ | ||
$params = array_merge(array( | ||
'notify_url' => '', | ||
'return_url' => '', | ||
'amount' => array( | ||
'currency' => 'USD', | ||
'value' => '', | ||
), | ||
'order' => array( | ||
'id' => null, | ||
'desc' => '', | ||
'extend_info' => array( | ||
'china_extra_trans_info' => array( | ||
'business_type' => '', | ||
), | ||
), | ||
), | ||
'payment_request_id' => null, | ||
), $params); | ||
|
||
$alipayPayRequest = new AlipayPayRequest(); | ||
$alipayPayRequest->setPath( | ||
'/ams/' . ($this->is_sandbox ? 'sandbox' : '') . '/api/v1/payments/pay' | ||
); | ||
$alipayPayRequest->setClientId($this->client_id); | ||
|
||
$alipayPayRequest->setProductCode(ProductCodeType::CASHIER_PAYMENT); | ||
$alipayPayRequest->setPaymentNotifyUrl($params['notify_url']); | ||
$alipayPayRequest->setPaymentRedirectUrl($params['return_url']); | ||
$alipayPayRequest->setPaymentRequestId($params['payment_request_id'] ?? self::CreatePaymentRequestId()); | ||
|
||
$paymentMethod = new PaymentMethod(); | ||
$paymentMethod->setPaymentMethodType(CustomerBelongsTo::ALIPAY_CN); | ||
$alipayPayRequest->setPaymentMethod($paymentMethod); | ||
|
||
$amount = new Amount(); | ||
$amount->setCurrency($params['amount']['currency']); | ||
$amount->setValue($params['amount']['value']); | ||
|
||
$order = new Order(); | ||
$order->setOrderDescription($params['order']['desc']); | ||
$order->setReferenceOrderId($params['order']['id'] ?? self::CreateOredrId()); | ||
$order->setOrderAmount($amount); | ||
|
||
$chinaExtraTransInfo = new ChinaExtraTransInfo(); | ||
$chinaExtraTransInfo->setBusinessType($params['order']['extend_info']['china_extra_trans_info']['business_type']); | ||
$extendInfo = $chinaExtraTransInfo; | ||
|
||
$extendInfo = new ExtendInfo(); | ||
$extendInfo->setChinaExtraTransInfo($chinaExtraTransInfo); | ||
$order->setExtendInfo($extendInfo . ''); | ||
|
||
$env = new Env(); | ||
$env->setTerminalType(TerminalType::WEB); | ||
$order->setEnv($env); | ||
|
||
$alipayPayRequest->setPaymentAmount($amount); | ||
$alipayPayRequest->setOrder($order); | ||
|
||
$settlementStrategy = new SettlementStrategy(); | ||
$settlementStrategy->setSettlementCurrency($params['amount']['currency']); | ||
$alipayPayRequest->setSettlementStrategy($settlementStrategy); | ||
|
||
try { | ||
return $this->alipayClient->execute($alipayPayRequest); | ||
} catch (Exception $e) { | ||
throw $e; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
namespace Mantoufan\model; | ||
|
||
class ChinaExtraTransInfo | ||
{ | ||
public $businessType; | ||
public $flightNumber; | ||
public $departureTime; | ||
public $hotelName; | ||
public $checkinTime; | ||
public $checkoutTime; | ||
public $admissionNoticeUrl; | ||
public $totalQuantity; | ||
public $goodsInfo; | ||
public $otherBusinessType; | ||
|
||
public function getBusinessType() | ||
{ | ||
return $this->businessType; | ||
} | ||
|
||
public function setBusinessType(String $businessType) | ||
{ | ||
$this->businessType = $businessType; | ||
} | ||
|
||
public function getFlightNumber() | ||
{ | ||
return $this->flightNumber; | ||
} | ||
|
||
public function setFlightNumber(String $flightNumber) | ||
{ | ||
$this->flightNumber = $flightNumber; | ||
} | ||
|
||
public function getDepartureTime() | ||
{ | ||
return $this->departureTime; | ||
} | ||
|
||
public function setDepartureTime(String $departureTime) | ||
{ | ||
$this->departureTime = $departureTime; | ||
} | ||
|
||
public function getHotelName() | ||
{ | ||
return $this->hotelName; | ||
} | ||
|
||
public function setHotelName(String $hotelName) | ||
{ | ||
$this->hotelName = $hotelName; | ||
} | ||
|
||
public function getCheckinTime() | ||
{ | ||
return $this->checkinTime; | ||
} | ||
|
||
public function setCheckinTime(String $checkinTime) | ||
{ | ||
$this->checkinTime = $checkinTime; | ||
} | ||
|
||
public function getCheckoutTime() | ||
{ | ||
return $this->checkoutTime; | ||
} | ||
|
||
public function setCheckoutTime(String $checkoutTime) | ||
{ | ||
$this->checkoutTime = $checkoutTime; | ||
} | ||
|
||
public function getAdmissionNoticeUrl() | ||
{ | ||
return $this->admissionNoticeUrl; | ||
} | ||
|
||
public function setAdmissionNoticeUrl(String $admissionNoticeUrl) | ||
{ | ||
$this->admissionNoticeUrl = $admissionNoticeUrl; | ||
} | ||
|
||
public function getTotalQuantity() | ||
{ | ||
return $this->totalQuantity; | ||
} | ||
|
||
public function setTotalQuantity(String $totalQuantity) | ||
{ | ||
$this->totalQuantity = $totalQuantity; | ||
} | ||
|
||
public function getGoodsInfo() | ||
{ | ||
return $this->goodsInfo; | ||
} | ||
|
||
public function setGoodsInfo(String $goodsInfo) | ||
{ | ||
$this->goodsInfo = $goodsInfo; | ||
} | ||
|
||
public function getOtherBusinessType() | ||
{ | ||
return $this->otherBusinessType; | ||
} | ||
|
||
public function setOtherBusinessType(String $otherBusinessType) | ||
{ | ||
$this->otherBusinessType = $otherBusinessType; | ||
} | ||
} |
Oops, something went wrong.