-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #204 from xiaozan/master
支付宝小程序支付
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 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
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,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'; | ||
} | ||
} |