Skip to content

Commit

Permalink
Merge pull request #204 from xiaozan/master
Browse files Browse the repository at this point in the history
支付宝小程序支付
  • Loading branch information
yansongda authored Dec 18, 2018
2 parents 47bcb8b + a4aafb2 commit 758387a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ QQ交流群:690027516
- 刷卡支付
- 扫码支付
- 账户转账
- 小程序支付

| method | 描述 |
| :-------: | :-------: |
Expand All @@ -60,6 +61,7 @@ QQ交流群:690027516
| pos | 刷卡支付 |
| scan | 扫码支付 |
| transfer | 帐户转账 |
| mini | 小程序支付 |

### 2、微信
- 公众号支付
Expand Down
1 change: 1 addition & 0 deletions src/Gateways/Alipay.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @method Collection transfer(array $config) 帐户转账
* @method Response wap(array $config) 手机网站支付
* @method Response web(array $config) 电脑支付
* @method Collection mini(array $config) 小程序支付
*/
class Alipay implements GatewayApplicationInterface
{
Expand Down
53 changes: 53 additions & 0 deletions src/Gateways/Alipay/MiniGateway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Yansongda\Pay\Gateways\Alipay;

use Yansongda\Pay\Contracts\GatewayInterface;
use Yansongda\Pay\Events;
use Yansongda\Supports\Collection;

class MiniGateway implements GatewayInterface
{
/**
* Pay an order.
*
* @author xiaozan <[email protected]>
*
* @param string $endpoint
* @param array $payload
*
* @throws \Yansongda\Pay\Exceptions\GatewayException
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws \Yansongda\Pay\Exceptions\InvalidConfigException
* @throws \Yansongda\Pay\Exceptions\InvalidSignException
*
* @link https://docs.alipay.com/mini/introduce/pay
*
* @return Collection
*/
public function pay($endpoint, array $payload): Collection
{
if (empty(json_decode($payload['biz_content'], true)['buyer_id'])) {
throw new \Yansongda\Pay\Exceptions\InvalidArgumentException('buyer_id required');
}

$payload['method'] = $this->getMethod();
$payload['sign'] = Support::generateSign($payload);

Events::dispatch(Events::PAY_STARTED, new Events\PayStarted('Alipay', 'Mini', $endpoint, $payload));

return Support::requestApi($payload);
}

/**
* Get method config.
*
* @author yansongda <[email protected]>
*
* @return string
*/
protected function getMethod(): string
{
return 'alipay.trade.create';
}
}

0 comments on commit 758387a

Please sign in to comment.