Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
liyangmsn committed Oct 5, 2020
1 parent c5cde9b commit 2188159
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 34 deletions.
7 changes: 4 additions & 3 deletions src/Contracts/PaymentInterface.php
Expand Up @@ -2,12 +2,13 @@

namespace PaymentChannel\Contracts;

interface PaymentInterface {
interface PaymentInterface
{
public function pay(array $params): array;

public function unify(array $params, array $options = []): array;

public function query(string $out_trade_no): array;

public function refund(string $out_trade_no, string $refund_no, int $total_fee, int $refund_fee, array $config): array;
}
public function refund(string $out_trade_no, string $refund_no, float $total_fee, float $refund_fee, array $config = []): array;
}
23 changes: 15 additions & 8 deletions src/Official/Alipay/Application.php
Expand Up @@ -6,13 +6,15 @@
use PaymentChannel\Kernel\BaseApplication;
use PaymentChannel\Kernel\Alipay;

class Application extends BaseApplication implements PaymentInterface {
class Application extends BaseApplication implements PaymentInterface
{
private $payment;
private $auth_token;
private $app_auth_token;
private $target_app_id;

public function __construct(\PaymentChannel\Official\Application $app) {
public function __construct(\PaymentChannel\Official\Application $app)
{
parent::__construct($app);
$config = $this->app->getConfig();
$this->payment = new Alipay($config['alipay']);
Expand All @@ -25,14 +27,16 @@ public function __construct(\PaymentChannel\Official\Application $app) {
}
}

public function pay(array $params): array {
public function pay(array $params): array
{
$request = new \AlipayTradePayRequest();
$request->setBizContent(json_encode($params));
$result = $this->payment->execute($request, $this->auth_token, $this->app_auth_token, $this->target_app_id);
return $this->_object_to_array($result);
}

public function unify(array $params, array $options = []): array {
public function unify(array $params, array $options = []): array
{
$request = new \AlipayTradeCreateRequest();
$request->setBizContent(json_encode($params));
if (array_key_exists('notify_url', $options)) {
Expand All @@ -42,7 +46,8 @@ public function unify(array $params, array $options = []): array {
return $this->_object_to_array($result);
}

public function query(string $out_trade_no): array {
public function query(string $out_trade_no): array
{
$request = new \AlipayTradeQueryRequest();
$request->setBizContent(json_encode([
'out_trade_no' => $out_trade_no
Expand All @@ -51,7 +56,8 @@ public function query(string $out_trade_no): array {
return $this->_object_to_array($result);
}

public function refund(string $out_trade_no, string $refund_no, int $total_fee, int $refund_fee, array $config = null): array {
public function refund(string $out_trade_no, string $refund_no, float $total_fee, float $refund_fee, array $config = []): array
{
$request = new \AlipayTradeRefundRequest();
$request->setBizContent(json_encode(array_merge([
'out_trade_no' => $out_trade_no,
Expand All @@ -61,7 +67,8 @@ public function refund(string $out_trade_no, string $refund_no, int $total_fee,
return $this->_object_to_array($result);
}

private function _object_to_array($obj) {
private function _object_to_array($obj)
{
$obj = (array)$obj;
foreach ($obj as $k => $v) {
if (gettype($v) == 'resource') {
Expand All @@ -74,4 +81,4 @@ private function _object_to_array($obj) {

return $obj;
}
}
}
20 changes: 13 additions & 7 deletions src/Official/Wechat/Application.php
Expand Up @@ -6,28 +6,34 @@
use PaymentChannel\Kernel\BaseApplication;
use EasyWeChat\Payment\Application as Payment;

class Application extends BaseApplication implements PaymentInterface {
class Application extends BaseApplication implements PaymentInterface
{
private $payment;

public function __construct(\PaymentChannel\Official\Application $app) {
public function __construct(\PaymentChannel\Official\Application $app)
{
parent::__construct($app);
$config = $this->app->getConfig();
$this->payment = new Payment($config['wechat']);
}

public function pay(array $params): array {
public function pay(array $params): array
{
return $this->payment->pay($params);
}

public function unify(array $params, array $options = []): array {
public function unify(array $params, array $options = []): array
{
return $this->payment->order->unify($params);
}

public function query(string $out_trade_no): array {
public function query(string $out_trade_no): array
{
return $this->payment->order->queryByOutTradeNumber($out_trade_no);
}

public function refund(string $out_trade_no, string $refund_no, int $total_fee, int $refund_fee, array $config): array {
public function refund(string $out_trade_no, string $refund_no, float $total_fee, float $refund_fee, array $config = []): array
{
return $this->payment->refund->byOutTradeNumber($out_trade_no, $refund_no, $total_fee, $refund_fee, $config);
}
}
}
24 changes: 15 additions & 9 deletions src/SwiftPass/Application.php
Expand Up @@ -6,35 +6,41 @@
use PaymentChannel\Kernel\BaseApplication;
use PaymentChannel\Kernel\SwiftPass\Client;

class Application extends BaseApplication implements PaymentInterface {
class Application extends BaseApplication implements PaymentInterface
{
private $payment;
private $config;

public function __construct($config) {
public function __construct($config)
{
$this->config = $config;
$this->payment = new Client($config);
}

public function pay(array $params): array {
public function pay(array $params): array
{
return $this->payment->execute($params, 'unified.trade.micropay');
}

public function unify(array $params, array $options = []): array {
public function unify(array $params, array $options = []): array
{
return $this->payment->execute($params, $options['service']);
}

public function query(string $out_trade_no): array {
public function query(string $out_trade_no): array
{
return $this->payment->execute([
'out_trade_no' => $out_trade_no
], 'unified.trade.query');
}

public function refund(string $out_trade_no, string $refund_no, int $total_fee, int $refund_fee, array $config): array {
return $this->payment->execute([
public function refund(string $out_trade_no, string $refund_no, float $total_fee, float $refund_fee, array $config = []): array
{
return $this->payment->execute(array_merge([
'out_trade_no' => $out_trade_no,
'out_refund_no' => $refund_no,
'total_fee' => $total_fee,
'refund_fee' => $refund_fee
], 'unified.trade.refund');
], $config), 'unified.trade.refund');
}
}
}
20 changes: 13 additions & 7 deletions src/Sxf/Application.php
Expand Up @@ -10,32 +10,37 @@
use PaymentChannel\Kernel\Sxf\Request\SxfQrReverseScanRequest;
use PaymentChannel\Kernel\Sxf\SxfClient;

class Application extends BaseApplication implements PaymentInterface {
class Application extends BaseApplication implements PaymentInterface
{
private $payment;
private $config;

public function __construct($config) {
public function __construct($config)
{
$this->config = $config;
$this->payment = new SxfClient($this->config);
}

public function pay(array $params): array {
public function pay(array $params): array
{
$request = new SxfQrReverseScanRequest();
$request->setBizContent(array_merge([
'mno' => $this->config['mno'],
], $params));
return $this->payment->execute($request);
}

public function unify(array $params, array $options = []): array {
public function unify(array $params, array $options = []): array
{
$request = new SxfQrJsApiScanRequest();
$request->setBizContent(array_merge([
'mno' => $this->config['mno'],
], $params));
return $this->payment->execute($request);
}

public function query(string $out_trade_no): array {
public function query(string $out_trade_no): array
{
$request = new SxfQrQueryRequest();
$request->setBizContent([
'mno' => $this->config['mno'],
Expand All @@ -44,7 +49,8 @@ public function query(string $out_trade_no): array {
return $this->payment->execute($request);
}

public function refund(string $out_trade_no, string $refund_no, int $total_fee, int $refund_fee, array $config): array {
public function refund(string $out_trade_no, string $refund_no, float $total_fee, float $refund_fee, array $config = []): array
{
$request = new SxfQrRefundRequest();
$request->setBizContent([
'mno' => $this->config['mno'],
Expand All @@ -55,4 +61,4 @@ public function refund(string $out_trade_no, string $refund_no, int $total_fee,
]);
return $this->payment->execute($request);
}
}
}

0 comments on commit 2188159

Please sign in to comment.