<?php
namespace Alipay\EasySDK\Payment\Page;
use Alipay\EasySDK\Kernel\EasySDKKernel;
use Alipay\EasySDK\Payment\Page\Models\AlipayTradePagePayResponse;
class Client {
protected $_kernel;
public function __construct($kernel){
$this->_kernel = $kernel;
}
public function pay($subject, $outTradeNo, $totalAmount, $returnUrl){
$systemParams = [
"method" => "alipay.trade.page.pay",
"app_id" => $this->_kernel->getConfig("appId"),
"timestamp" => $this->_kernel->getTimestamp(),
"format" => "json",
"version" => "1.0",
"alipay_sdk" => $this->_kernel->getSdkVersion(),
"charset" => "UTF-8",
"sign_type" => $this->_kernel->getConfig("signType"),
"app_cert_sn" => $this->_kernel->getMerchantCertSN(),
"alipay_root_cert_sn" => $this->_kernel->getAlipayRootCertSN()
];
$bizParams = [
"subject" => $subject,
"out_trade_no" => $outTradeNo,
"total_amount" => $totalAmount,
"product_code" => "FAST_INSTANT_TRADE_PAY"
];
$textParams = [
"return_url" => $returnUrl
];
$sign = $this->_kernel->sign($systemParams, $bizParams, $textParams, $this->_kernel->getConfig("merchantPrivateKey"));
$response = [
"body" => $this->_kernel->generatePage("POST", $systemParams, $bizParams, $textParams, $sign)
];
return AlipayTradePagePayResponse::fromMap($response);
}
public function agent($appAuthToken)
{
$this->_kernel->injectTextParam("app_auth_token", $appAuthToken);
return $this;
}
public function auth($authToken)
{
$this->_kernel->injectTextParam("auth_token", $authToken);
return $this;
}
public function asyncNotify($url)
{
$this->_kernel->injectTextParam("notify_url", $url);
return $this;
}
public function route($testUrl)
{
$this->_kernel->injectTextParam("ws_service_url", $testUrl);
return $this;
}
public function optional($key, $value)
{
$this->_kernel->injectBizParam($key, $value);
return $this;
}
public function batchOptional($optionalArgs)
{
foreach ($optionalArgs as $key => $value) {
$this->_kernel->injectBizParam($key, $value);
}
return $this;
}
}