Skip to content
This repository has been archived by the owner on Apr 1, 2019. It is now read-only.

Commit

Permalink
Merge pull request #3 from RunnerLee/analysis-8Lv6eG
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
RunnerLee authored Jun 21, 2018
2 parents 902c693 + cb0006c commit e716d39
Show file tree
Hide file tree
Showing 24 changed files with 275 additions and 263 deletions.
2 changes: 1 addition & 1 deletion src/Cashier.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Runner\NezhaCashier;

use InvalidArgumentException;
use Runner\NezhaCashier\Contracts\GatewayInterface;
use Runner\NezhaCashier\Exception\InvalidNotificationException;
use Runner\NezhaCashier\Gateways\AbstractGateway;
Expand All @@ -15,7 +16,6 @@
use Runner\NezhaCashier\Responses\Refund;
use Runner\NezhaCashier\Utils\AbstractOption;
use Runner\NezhaCashier\Utils\Collection;
use InvalidArgumentException;
use Runner\NezhaCashier\Utils\Config;
use Runner\NezhaCashier\Utils\Str;

Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/GatewayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
namespace Runner\NezhaCashier\Contracts;

use Runner\NezhaCashier\Requests\Charge;
use Runner\NezhaCashier\Requests\Refund;
use Runner\NezhaCashier\Requests\Close;
use Runner\NezhaCashier\Requests\Query;
use Runner\NezhaCashier\Requests\Refund;

interface GatewayInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/RequestGatewayException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace Runner\NezhaCashier\Exception;

use RuntimeException;
use GuzzleHttp\Exception\RequestException;
use RuntimeException;

class RequestGatewayException extends RuntimeException
{
Expand Down
66 changes: 33 additions & 33 deletions src/Gateways/Alipay/AbstractAlipayGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\RequestOptions;
use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface;
use Runner\NezhaCashier\Exception\GatewayException;
use Runner\NezhaCashier\Exception\GatewayMethodNotSupportException;
Expand All @@ -18,7 +19,6 @@
use Runner\NezhaCashier\Requests\Close;
use Runner\NezhaCashier\Requests\Query;
use Runner\NezhaCashier\Requests\Refund;
use InvalidArgumentException;
use Runner\NezhaCashier\Utils\Amount;
use Runner\NezhaCashier\Utils\HttpClient;

Expand All @@ -37,8 +37,8 @@ public function charge(Charge $form): array
[
'out_trade_no' => $form->get('order_id'),
'total_amount' => Amount::centToDollar($form->get('amount')),
'subject' => $form->get('subject'),
'body' => $form->get('description'),
'subject' => $form->get('subject'),
'body' => $form->get('description'),
],
$this->prepareCharge($form),
$form->get('extras')
Expand Down Expand Up @@ -74,9 +74,9 @@ public function refund(Refund $form): array
'alipay.trade.refund',
array_merge(
[
'out_trade_no' => $form->get('order_id'),
'refund_amount' => Amount::centToDollar($form->get('refund_amount')),
'refund_reason' => $form->get('reason'),
'out_trade_no' => $form->get('order_id'),
'refund_amount' => Amount::centToDollar($form->get('refund_amount')),
'refund_reason' => $form->get('reason'),
'out_request_no' => $form->get('refund_id'),
],
$form->get('extras')
Expand All @@ -90,9 +90,9 @@ public function refund(Refund $form): array
}

return [
'refund_sn' => $response['trade_no'],
'refund_sn' => $response['trade_no'],
'refund_amount' => Amount::dollarToCent($response['refund_fee']),
'raw' => $response,
'raw' => $response,
];
}

Expand Down Expand Up @@ -127,22 +127,22 @@ public function query(Query $form): array
'alipay.trade.query',
[
'out_trade_no' => $form->get('order_id'),
'trade_no' => $form->get('trade_sn'),
'trade_no' => $form->get('trade_sn'),
]
);

$result = $this->request($payload);

return [
'order_id' => $result['out_trade_no'],
'status' => $this->formatTradeStatus($result['trade_status']),
'trade_sn' => $result['trade_no'],
'order_id' => $result['out_trade_no'],
'status' => $this->formatTradeStatus($result['trade_status']),
'trade_sn' => $result['trade_no'],
'buyer_identifiable_id' => $result['buyer_user_id'],
'amount' => Amount::dollarToCent($result['total_amount']),
'buyer_name' => $result['buyer_logon_id'],
'amount' => Amount::dollarToCent($result['total_amount']),
'buyer_name' => $result['buyer_logon_id'],
// 支付宝打款时间, 作为付款时间有些争议
'paid_at' => isset($result['send_pay_date']) ? strtotime($result['send_pay_date']) : 0,
'raw' => $result,
'raw' => $result,
];
}

Expand All @@ -154,14 +154,14 @@ public function query(Query $form): array
public function chargeNotify(array $receives): array
{
return [
'order_id' => $receives['out_trade_no'],
'status' => $this->formatTradeStatus($receives['trade_status']),
'trade_sn' => $receives['trade_no'],
'order_id' => $receives['out_trade_no'],
'status' => $this->formatTradeStatus($receives['trade_status']),
'trade_sn' => $receives['trade_no'],
'buyer_identifiable_id' => $receives['buyer_id'],
'amount' => Amount::dollarToCent($receives['receipt_amount'] ?? 0),
'buyer_name' => '',
'paid_at' => (isset($receives['gmt_payment']) ? strtotime($receives['gmt_payment']) : 0),
'raw' => $receives,
'amount' => Amount::dollarToCent($receives['receipt_amount'] ?? 0),
'buyer_name' => '',
'paid_at' => (isset($receives['gmt_payment']) ? strtotime($receives['gmt_payment']) : 0),
'raw' => $receives,
];
}

Expand Down Expand Up @@ -259,15 +259,15 @@ public function convertNotificationToArray($receives): array
protected function createPayload($method, array $content, $notifyUrl = '', $returnUrl = '')
{
$parameters = [
'app_id' => $this->config->get('app_id'),
'method' => $method,
'format' => 'JSON',
'return_url' => $returnUrl,
'charset' => 'utf8',
'sign_type' => 'RSA2',
'timestamp' => date('Y-m-d H:i:s'),
'version' => '1.0',
'notify_url' => $notifyUrl,
'app_id' => $this->config->get('app_id'),
'method' => $method,
'format' => 'JSON',
'return_url' => $returnUrl,
'charset' => 'utf8',
'sign_type' => 'RSA2',
'timestamp' => date('Y-m-d H:i:s'),
'version' => '1.0',
'notify_url' => $notifyUrl,
'biz_content' => json_encode($content),
];
$parameters['sign'] = $this->sign($parameters);
Expand Down Expand Up @@ -384,9 +384,9 @@ function ($value) {
protected function formatTradeStatus($status): string
{
$map = [
'TRADE_SUCCESS' => 'paid',
'TRADE_SUCCESS' => 'paid',
'WAIT_BUYER_PAY' => 'created',
'TRADE_CLOSED' => 'closed',
'TRADE_CLOSED' => 'closed',
];

return $map[$status];
Expand Down
100 changes: 50 additions & 50 deletions src/Gateways/Paypal/ExpressCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ public function query(Query $form): array
}

return [
'order_id' => $form->get('order_id'),
'status' => 'paid',
'trade_sn' => $result['L_TRANSACTIONID0'],
'order_id' => $form->get('order_id'),
'status' => 'paid',
'trade_sn' => $result['L_TRANSACTIONID0'],
'buyer_identifiable_id' => $result['L_EMAIL0'],
'buyer_name' => $result['L_EMAIL0'],
'buyer_email' => $result['L_EMAIL0'],
'amount' => Amount::dollarToCent($result['L_AMT0']),
'tax' => abs($result['L_FEEAMT0'] ?? 0),
'raw' => $result,
'buyer_name' => $result['L_EMAIL0'],
'buyer_email' => $result['L_EMAIL0'],
'amount' => Amount::dollarToCent($result['L_AMT0']),
'tax' => abs($result['L_FEEAMT0'] ?? 0),
'raw' => $result,
];
}

Expand All @@ -116,19 +116,19 @@ public function chargeNotify(array $receives): array
$transaction = $this->queryTransaction($receives['custom']);

return [
'order_id' => $receives['custom'],
'status' => 'paid',
'trade_sn' => $receives['txn_id'],
'amount' => Amount::dollarToCent($receives['payment_gross']),
'buyer_name' => $transaction['L_NAME0'],
'buyer_email' => $transaction['L_EMAIL0'] ?? '',
'currency' => $receives['mc_currency'],
'order_id' => $receives['custom'],
'status' => 'paid',
'trade_sn' => $receives['txn_id'],
'amount' => Amount::dollarToCent($receives['payment_gross']),
'buyer_name' => $transaction['L_NAME0'],
'buyer_email' => $transaction['L_EMAIL0'] ?? '',
'currency' => $receives['mc_currency'],
'buyer_identifiable_id' => $transaction['L_EMAIL0'],
'paid_at' => strtotime($receives['payment_date']),
'tax' => $receives['payment_fee'],
'raw' => [
'paid_at' => strtotime($receives['payment_date']),
'tax' => $receives['payment_fee'],
'raw' => [
'notification' => $receives,
'query' => $transaction,
'query' => $transaction,
],
];
}
Expand Down Expand Up @@ -233,18 +233,18 @@ protected function setCharge(Charge $form): array
$payload = $this->createPayload(
array_merge(
[
'METHOD' => 'SetExpressCheckout',
'AMT' => Amount::centToDollar($form->get('amount')),
'CUSTOM' => $form->get('order_id'),
'CURRENCYCODE' => strtoupper($form->get('currency')),
'PAYMENTACTION' => 'Sale',
'CANCELURL' => $form->get('return_url'),
'RETURNURL' => $form->get('return_url'),
'INVNUM' => $form->get('order_id'),
'DESC' => $form->get('description'),
'BRANDNAME' => $this->config->get('brand_name'),
'NOSHIPPING' => 1,
'NOTIFYURL' => $this->config->get('notify_url'),
'METHOD' => 'SetExpressCheckout',
'AMT' => Amount::centToDollar($form->get('amount')),
'CUSTOM' => $form->get('order_id'),
'CURRENCYCODE' => strtoupper($form->get('currency')),
'PAYMENTACTION' => 'Sale',
'CANCELURL' => $form->get('return_url'),
'RETURNURL' => $form->get('return_url'),
'INVNUM' => $form->get('order_id'),
'DESC' => $form->get('description'),
'BRANDNAME' => $this->config->get('brand_name'),
'NOSHIPPING' => 1,
'NOTIFYURL' => $this->config->get('notify_url'),
'PAYMENTREQUEST_0_NOTIFYURL' => $this->config->get('notify_url'),
],
$form->get('extras')
Expand All @@ -256,9 +256,9 @@ protected function setCharge(Charge $form): array
return [
'charge_url' => self::WEB_GATEWAY.'?'.http_build_query(
[
'cmd' => '_express-checkout-mobile',
'cmd' => '_express-checkout-mobile',
'useraction' => 'commit',
'token' => $result['TOKEN'],
'token' => $result['TOKEN'],
]
),
];
Expand All @@ -274,7 +274,7 @@ protected function doCharge(Charge $form): array
$payload = $this->createPayload(
array_merge(
[
'METHOD' => 'DoExpressCheckoutPayment',
'METHOD' => 'DoExpressCheckoutPayment',
'PAYMENTREQUEST_0_AMT' => Amount::centToDollar($form->get('amount')),
// 'TOKEN' => $form->find('extras.token'),
// 'PAYERID' => $form->find('extras.payer_id'),
Expand All @@ -300,18 +300,18 @@ protected function doCharge(Charge $form): array
return [
'charge_url' => '',
'parameters' => [
'order_id' => $form->get('order_id'),
'status' => 'paid',
'trade_sn' => $result['PAYMENTINFO_0_TRANSACTIONID'],
'order_id' => $form->get('order_id'),
'status' => 'paid',
'trade_sn' => $result['PAYMENTINFO_0_TRANSACTIONID'],
'buyer_identifiable_id' => $transaction['L_EMAIL0'],
'amount' => Amount::dollarToCent($result['PAYMENTINFO_0_AMT']),
'tax' => $result['PAYMENTINFO_0_FEEAMT'],
'currency' => $result['PAYMENTINFO_0_CURRENCYCODE'],
'buyer_name' => $transaction['L_NAME0'],
'buyer_email' => $transaction['L_EMAIL0'],
'paid_at' => strtotime($result['TIMESTAMP']),
'charge_raw' => $result,
'query_raw' => $transaction,
'amount' => Amount::dollarToCent($result['PAYMENTINFO_0_AMT']),
'tax' => $result['PAYMENTINFO_0_FEEAMT'],
'currency' => $result['PAYMENTINFO_0_CURRENCYCODE'],
'buyer_name' => $transaction['L_NAME0'],
'buyer_email' => $transaction['L_EMAIL0'],
'paid_at' => strtotime($result['TIMESTAMP']),
'charge_raw' => $result,
'query_raw' => $transaction,
],
];
}
Expand All @@ -327,9 +327,9 @@ protected function queryTransaction($orderId, array $extras = []): array
$payload = $this->createPayload(
array_merge(
[
'METHOD' => 'TransactionSearch',
'METHOD' => 'TransactionSearch',
'STARTDATE' => date('Y-m-d\TH:i:s\Z', $this->config->get('started_at')),
'INVNUM' => $orderId,
'INVNUM' => $orderId,
],
$extras
)
Expand All @@ -349,10 +349,10 @@ protected function createPayload(array $parameters): array
{
return array_merge(
[
'USER' => $this->config->get('user'),
'PWD' => $this->config->get('password'),
'USER' => $this->config->get('user'),
'PWD' => $this->config->get('password'),
'SIGNATURE' => $this->config->get('signature'),
'VERSION' => 88,
'VERSION' => 88,
],
$parameters
);
Expand Down
Loading

0 comments on commit e716d39

Please sign in to comment.