Skip to content

Commit

Permalink
chore: change abstraction level
Browse files Browse the repository at this point in the history
  • Loading branch information
enggar appkey committed Jun 24, 2022
1 parent 07b3734 commit 674c5ed
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 50 deletions.
6 changes: 3 additions & 3 deletions src/Contract/PaymentMethod/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Nekoding\LaravelSoftbank\Contract\PaymentService;
use Nekoding\LaravelSoftbank\Contract\Response;

interface CreditCard extends PaymentService
abstract class CreditCard extends PaymentService
{

/**
Expand All @@ -15,14 +15,14 @@ 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
*
* @param \Nekoding\LaravelSoftbank\Contract\Payload $payload
* @return Response
*/
public function saveCard(Payload $payload): Response;
public abstract function saveCard(Payload $payload): Response;

}
39 changes: 33 additions & 6 deletions src/Contract/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,45 @@

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
*
* @param \Nekoding\LaravelSoftbank\Contract\Payload $payload
* @return Response
*/
public function createTransaction(Payload $payload): Response;
public abstract function createTransaction(Payload $payload): Response;


/**
Expand All @@ -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;


/**
Expand All @@ -31,13 +58,13 @@ 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
*
* @param \Nekoding\LaravelSoftbank\Contract\Payload $payload
* @return Response
*/
public function refundTransaction(Payload $payload): Response;
public abstract function refundTransaction(Payload $payload): Response;
}
25 changes: 1 addition & 24 deletions src/PaymentMethod/CreditCard/CreditCardPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down
17 changes: 0 additions & 17 deletions src/Traits/Payload/CanChangeRequestId.php

This file was deleted.

0 comments on commit 674c5ed

Please sign in to comment.