Skip to content

Commit

Permalink
update php cs
Browse files Browse the repository at this point in the history
  • Loading branch information
Recca Tsai committed Jan 18, 2017
1 parent 7de4d78 commit 242084b
Show file tree
Hide file tree
Showing 16 changed files with 168 additions and 176 deletions.
105 changes: 68 additions & 37 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,69 +5,100 @@ use Symfony\CS\Config\Config;
use Symfony\CS\FixerInterface;

$fixers = [
'blankline_after_open_tag',
'binary_operator_spaces',
'blank_line_after_namespace',
'blank_line_after_opening_tag',
'blank_line_before_return',
'braces',
'cast_spaces',
'class_definition',
'concat_without_spaces',
'double_arrow_multiline_whitespaces',
'duplicate_semicolon',
'declare_equal_normalize',
'elseif',
'empty_return',
'encoding',
'eof_ending',
'extra_empty_lines',
'function_call_space',
'full_opening_tag',
'function_declaration',
'function_typehint_space',
'hash_to_slash_comment',
'heredoc_to_nowdoc',
'include',
'indentation',
'join_function',
'line_after_namespace',
'linefeed',
'list_commas',
'logical_not_operators_with_successor_space',
'length_ordered_imports',
'lowercase_cast',
'lowercase_constants',
'lowercase_keywords',
'method_argument_space',
'multiline_array_trailing_comma',
'multiline_spaces_before_semicolon',
'multiple_use',
'namespace_no_leading_whitespace',
'method_separation',
'method_visibility_required',
'native_function_casing',
'no_alias_functions',
'no_blank_lines_after_class_opening',
'no_empty_lines_after_phpdocs',
'object_operator',
'operators_spaces',
'parenthesis',
'no_blank_lines_after_phpdoc',
'no_blank_lines_after_throw',
'no_blank_lines_between_imports',
'no_blank_lines_between_traits',
'no_closing_tag',
'no_empty_phpdoc',
'no_empty_statement',
'no_extra_consecutive_blank_lines',
'no_leading_import_slash',
'no_leading_namespace_whitespace',
'no_multiline_whitespace_around_double_arrow',
'no_multiline_whitespace_before_semicolons',
'no_short_bool_cast',
'no_singleline_whitespace_before_semicolons',
'no_spaces_after_function_name',
'no_spaces_inside_offset',
'no_spaces_inside_parenthesis',
'no_tab_indentation',
'no_trailing_comma_in_list_call',
'no_trailing_comma_in_singleline_array',
'no_trailing_whitespace',
'no_trailing_whitespace_in_comment',
'no_unneeded_control_parentheses',
'no_unreachable_default_argument_value',
'no_unused_imports',
'no_useless_return',
'no_whitespace_before_comma_in_array',
'no_whitespace_in_blank_line',
'normalize_index_brace',
'not_operator_with_successor_space',
'object_operator_without_whitespace',
'phpdoc_indent',
'phpdoc_inline_tag',
'phpdoc_no_access',
'phpdoc_no_package',
'phpdoc_scalar',
'phpdoc_short_description',
'phpdoc_single_line_var_spacing',
'phpdoc_summary',
'phpdoc_to_comment',
'phpdoc_trim',
'phpdoc_type_to_var',
'phpdoc_types',
'phpdoc_var_without_name',
'remove_leading_slash_use',
'remove_lines_between_uses',
'return',
'print_to_echo',
'property_visibility_required',
'psr4',
'self_accessor',
'short_array_syntax',
'short_echo_tag',
'short_tag',
'single_array_no_trailing_comma',
'short_scalar_cast',
'simplified_null_return',
'single_blank_line_at_eof',
'single_blank_line_before_namespace',
'single_class_element_per_statement',
'single_import_per_statement',
'single_line_after_imports',
'single_quote',
'spaces_before_semicolon',
'spaces_cast',
'standardize_not_equal',
'ternary_spaces',
'trailing_spaces',
'space_after_semicolon',
'standardize_not_equals',
'switch_case_semicolon_to_colon',
'switch_case_space',
'ternary_operator_spaces',
'trailing_comma_in_multiline_array',
'trim_array_spaces',
'unalign_equals',
'unary_operators_spaces',
'unused_use',
'visibility',
'whitespacy_lines',
'unary_operator_spaces',
'unix_line_endings',
'whitespace_after_comma_in_array',
];

return Config::create()
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The Payum extension to rapidly build new extensions.
$ composer create-project payum-tw/esunbank
```

2. Replace all occurrences of `payum` with your vendor name. It may be your github name, for now let's say you choose: `acme`.
2. Replace all occurrences of `payum` with your vendor name. It may be your github name, for now let's say you choose: `esunbank`.
3. Replace all occurrences of `esunbank` with a payment gateway name. For example Stripe, Paypal etc. For now let's say you choose: `esunbank`.
4. Register a gateway factory to the payum's builder and create a gateway:

Expand All @@ -43,8 +43,7 @@ $payum = (new PayumBuilder)
'sandbox' => true,
])

->getPayum()
;
->getPayum();
```

5. While using the gateway implement all method where you get `Not implemented` exception:
Expand Down
8 changes: 1 addition & 7 deletions src/Action/Api/GetTransactionDataAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ public function execute($request)

$details = ArrayObject::ensureArrayObject($request->getModel());

$result = $this->api->getTransactionData((array) $details);

if (isset($result['RC']) === true && $result['RC'] === '-1') {
return;
}

$details->replace($result);
$details->replace($this->api->getTransactionData((array) $details));
}

/**
Expand Down
3 changes: 0 additions & 3 deletions src/Action/CancelAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace PayumTW\Esunbank\Action;

use Payum\Core\Request\Sync;
use Payum\Core\Request\Cancel;
use Payum\Core\GatewayAwareTrait;
use Payum\Core\GatewayAwareInterface;
Expand All @@ -27,8 +26,6 @@ public function execute($request)
$details = ArrayObject::ensureArrayObject($request->getModel());

$this->gateway->execute(new CancelTransaction($details));

$this->gateway->execute(new Sync($details));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Action/CaptureAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

namespace PayumTW\Esunbank\Action;

use Payum\Core\Request\Sync;
use Payum\Core\Request\Capture;
use Payum\Core\GatewayAwareTrait;
use Payum\Core\GatewayAwareInterface;
use Payum\Core\Action\ActionInterface;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Request\GetHttpRequest;
use PayumTW\Esunbank\Action\Api\BaseApiAwareAction;
use PayumTW\Esunbank\Request\Api\CreateTransaction;
use Payum\Core\Exception\RequestNotSupportedException;

class CaptureAction implements ActionInterface, GatewayAwareInterface
class CaptureAction extends BaseApiAwareAction implements ActionInterface, GatewayAwareInterface
{
use GatewayAwareTrait;

Expand All @@ -31,7 +31,7 @@ public function execute($request)
$this->gateway->execute($httpRequest);

if (isset($httpRequest->request['DATA']) === true) {
$this->gateway->execute(new Sync($details));
$details->replace($this->api->parseResponse($httpRequest->request['DATA']));

return;
}
Expand Down
3 changes: 0 additions & 3 deletions src/Action/RefundAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace PayumTW\Esunbank\Action;

use Payum\Core\Request\Sync;
use Payum\Core\Request\Refund;
use Payum\Core\GatewayAwareTrait;
use Payum\Core\GatewayAwareInterface;
Expand All @@ -27,8 +26,6 @@ public function execute($request)
$details = ArrayObject::ensureArrayObject($request->getModel());

$this->gateway->execute(new RefundTransaction($details));

$this->gateway->execute(new Sync($details));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Action/StatusAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function execute($request)
}

if ($details['RC'] === '00') {
if (isset($details['response']) === true && isset($details['response']['MACD'])) {
if (isset($details['MACD'])) {
$request->markCaptured();

return;
Expand Down
6 changes: 0 additions & 6 deletions src/Action/SyncAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Payum\Core\GatewayAwareInterface;
use Payum\Core\Action\ActionInterface;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Request\GetHttpRequest;
use PayumTW\Esunbank\Request\Api\GetTransactionData;
use Payum\Core\Exception\RequestNotSupportedException;

Expand All @@ -25,11 +24,6 @@ public function execute($request)
RequestNotSupportedException::assertSupports($this, $request);

$details = ArrayObject::ensureArrayObject($request->getModel());
$httpRequest = new GetHttpRequest();
$this->gateway->execute($httpRequest);
$details->replace([
'response' => $httpRequest->request,
]);

$this->gateway->execute(new GetTransactionData($details));
}
Expand Down
73 changes: 48 additions & 25 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,38 +146,35 @@ public function createTransaction(array $params)
*/
public function getTransactionData(array $params)
{
$details = [];

if (empty($params['response']) === false) {
parse_str(str_replace(',', '&', $params['response']['DATA']), $details);

if ($this->verifyHash($params['response']['MACD'], $details) === false) {
$details['RC'] = '-1';
}
} else {
$supportedParams = [
// 訂單編號, 由特約商店產生,不可重複,不可 包含【_】字元,英數限用大寫
'ONO' => '',
// 特店代碼
'MID' => $this->options['MID'],
];
$supportedParams = [
// 訂單編號, 由特約商店產生,不可重複,不可 包含【_】字元,英數限用大寫
'ONO' => '',
// 特店代碼
'MID' => $this->options['MID'],
];

$data = array_replace(
$supportedParams,
array_intersect_key($params, $supportedParams)
);
$data = array_replace(
$supportedParams,
array_intersect_key($params, $supportedParams)
);

$data['ONO'] = strtoupper($data['ONO']);
$data['ONO'] = strtoupper($data['ONO']);

$body = $this->doRequest($this->prepareRequestData($data), 'sync');
$response = json_decode($body['DATA'], true);
$details = $response['txnData'];
$details['response'] = $response;
}
$body = $this->doRequest($this->prepareRequestData($data), 'sync');
$response = json_decode($body['DATA'], true);
$details = $response['txnData'];
$details['response'] = $response;

return $details;
}

/**
* refundTransaction.
*
* @param array $params
*
* @return array
*/
public function refundTransaction(array $params)
{
$details = [];
Expand Down Expand Up @@ -208,6 +205,13 @@ public function refundTransaction(array $params)
return $details;
}

/**
* cancelTransaction.
*
* @param array $params
*
* @return array
*/
public function cancelTransaction(array $params)
{
$supportedParams = [
Expand Down Expand Up @@ -288,6 +292,25 @@ public function verifyHash($macd, $data)
return $result;
}

/**
* parseResponse.
*
* @param array $response
*
* @return array
*/
public function parseResponse($response)
{
$details = [];
parse_str(str_replace(',', '&', $response['DATA'], $details));

if ($this->verifyHash($response['MACD'], $details) === false) {
$details['RC'] = '-1';
}

return array_merge($response, $details);
}

/**
* isMobile.
*
Expand Down
Loading

0 comments on commit 242084b

Please sign in to comment.