diff --git a/src/Contract/PaymentMethod/CreditCard.php b/src/Contract/PaymentMethod/CreditCard.php index cb99bc2..9df509d 100644 --- a/src/Contract/PaymentMethod/CreditCard.php +++ b/src/Contract/PaymentMethod/CreditCard.php @@ -6,7 +6,7 @@ use Nekoding\LaravelSoftbank\Contract\PaymentService; use Nekoding\LaravelSoftbank\Contract\Response; -interface CreditCard extends PaymentService +abstract class CreditCard extends PaymentService { /** @@ -15,7 +15,7 @@ interface CreditCard extends PaymentService * @param \Nekoding\LaravelSoftbank\Contract\Payload $payload * @return Response */ - public function partialRefundTransaction(Payload $payload): Response; + public abstract function partialRefundTransaction(Payload $payload): Response; /** * saveCard @@ -23,6 +23,6 @@ public function partialRefundTransaction(Payload $payload): Response; * @param \Nekoding\LaravelSoftbank\Contract\Payload $payload * @return Response */ - public function saveCard(Payload $payload): Response; + public abstract function saveCard(Payload $payload): Response; } \ No newline at end of file diff --git a/src/Contract/PaymentService.php b/src/Contract/PaymentService.php index 20854b2..04f2e2b 100644 --- a/src/Contract/PaymentService.php +++ b/src/Contract/PaymentService.php @@ -2,10 +2,37 @@ namespace Nekoding\LaravelSoftbank\Contract; -interface PaymentService +use Nekoding\LaravelSoftbank\Contract\Payload; +use Nekoding\LaravelSoftbank\PaymentMethod\SoftbankResponse; +use Nekoding\LaravelSoftbank\Traits\HttpClient\SoftbankHttpClient; +use Nekoding\LaravelSoftbank\Traits\Payload\PayloadSerializer; + +abstract class PaymentService { - public function createRequest(Payload $payload, string $requestId): Response; + use PayloadSerializer; + use SoftbankHttpClient; + + /** + * createRequest + * + * @param \Nekoding\LaravelSoftbank\Contract\Payload $payload + * @param string $requestId + * @return Response + */ + public function createRequest(Payload $payload, string $requestId): Response + { + $body = $this->generatePayload($payload, $requestId); + + $response = $this->postData($body, ['username' => $payload->getAuthUsername(), 'password' => $payload->getAuthPassword()]); + + /** + * @var \Nekoding\LaravelSoftbank\PaymentMethod\SoftbankResponse + */ + $result = $this->deserializeData($response->body(), SoftbankResponse::class); + + return $result; + } /** * createTransaction @@ -13,7 +40,7 @@ public function createRequest(Payload $payload, string $requestId): Response; * @param \Nekoding\LaravelSoftbank\Contract\Payload $payload * @return Response */ - public function createTransaction(Payload $payload): Response; + public abstract function createTransaction(Payload $payload): Response; /** @@ -22,7 +49,7 @@ public function createTransaction(Payload $payload): Response; * @param \Nekoding\LaravelSoftbank\Contract\Payload $payload * @return Response */ - public function confirmTransaction(Payload $payload): Response; + public abstract function confirmTransaction(Payload $payload): Response; /** @@ -31,7 +58,7 @@ public function confirmTransaction(Payload $payload): Response; * @param \Nekoding\LaravelSoftbank\Contract\Payload $payload * @return Response */ - public function marksTransactionSales(Payload $payload): Response; + public abstract function marksTransactionSales(Payload $payload): Response; /** * refundTransaction @@ -39,5 +66,5 @@ public function marksTransactionSales(Payload $payload): Response; * @param \Nekoding\LaravelSoftbank\Contract\Payload $payload * @return Response */ - public function refundTransaction(Payload $payload): Response; + public abstract function refundTransaction(Payload $payload): Response; } diff --git a/src/PaymentMethod/CreditCard/CreditCardPayment.php b/src/PaymentMethod/CreditCard/CreditCardPayment.php index b422559..081f263 100644 --- a/src/PaymentMethod/CreditCard/CreditCardPayment.php +++ b/src/PaymentMethod/CreditCard/CreditCardPayment.php @@ -5,18 +5,9 @@ use Nekoding\LaravelSoftbank\Contract\Payload; use Nekoding\LaravelSoftbank\Contract\PaymentMethod\CreditCard; use Nekoding\LaravelSoftbank\Contract\Response; -use Nekoding\LaravelSoftbank\PaymentMethod\SoftbankResponse; -use Nekoding\LaravelSoftbank\Traits\HttpClient\SoftbankHttpClient; -use Nekoding\LaravelSoftbank\Traits\Payload\CanChangeRequestId; -use Nekoding\LaravelSoftbank\Traits\Payload\PayloadSerializer; -class CreditCardPayment implements CreditCard +class CreditCardPayment extends CreditCard { - - use PayloadSerializer; - use SoftbankHttpClient; - use CanChangeRequestId; - protected $paymentRequestId = 'ST01-00101-101'; protected $confirmationRequestId = 'ST02-00101-101'; protected $salesRequestId = 'ST02-00201-101'; @@ -33,20 +24,6 @@ class CreditCardPayment implements CreditCard protected $getCardInfoRequestId = ''; - public function createRequest(Payload $payload, string $requestId): Response - { - $body = $this->generatePayload($payload, $requestId); - - $response = $this->postData($body, ['username' => $payload->getAuthUsername(), 'password' => $payload->getAuthPassword()]); - - /** - * @var \Nekoding\LaravelSoftbank\PaymentMethod\SoftbankResponse - */ - $result = $this->deserializeData($response->body(), SoftbankResponse::class); - - return $result; - } - public function createTransaction(Payload $payload): Response { return $this->createRequest($payload, $this->paymentRequestId); diff --git a/src/Traits/Payload/CanChangeRequestId.php b/src/Traits/Payload/CanChangeRequestId.php deleted file mode 100644 index 43a7727..0000000 --- a/src/Traits/Payload/CanChangeRequestId.php +++ /dev/null @@ -1,17 +0,0 @@ -requestId = $requestId; - - return $this; - } - -} \ No newline at end of file