From 03d407def3e9ec20519cf27cb4bba7668fe0540e Mon Sep 17 00:00:00 2001 From: r-kujawa Date: Fri, 19 Apr 2024 06:45:07 -0600 Subject: [PATCH] Rename "Payment" to "Checkout" where relevant --- composer.json | 4 +- config/checkout.php | 8 +- database/factories/PaymentMethodFactory.php | 1 - .../PaymentTransactionEventFactory.php | 12 +- .../factories/PaymentTransactionFactory.php | 4 +- ...PaymentGateway.php => CheckoutGateway.php} | 2 +- src/CheckoutRequest.php | 19 +++ src/CheckoutResponse.php | 54 +++++++++ ...ovider.php => CheckoutServiceProvider.php} | 6 +- src/{PaymentStatus.php => CheckoutStatus.php} | 110 +++++++++--------- ...entRequestor.php => CheckoutRequester.php} | 40 +++---- ...entResponder.php => CheckoutResponder.php} | 6 +- src/Facades/Checkout.php | 42 +++++++ src/Facades/Payment.php | 42 ------- .../Traits/ConfiguresPaymentGateway.php | 8 +- src/Models/Traits/PaymentMethodRequests.php | 6 +- .../Traits/PaymentTransactionRequests.php | 6 +- src/Models/Traits/WalletRequests.php | 2 +- src/PaymentRequest.php | 19 --- src/PaymentResponse.php | 54 --------- ...ymentRequests.php => CheckoutRequests.php} | 40 +++---- ...entResponses.php => CheckoutResponses.php} | 4 +- tests/TestCase.php | 4 +- tests/Unit/TestCheckoutGateway.php | 74 ++++++------ 24 files changed, 283 insertions(+), 284 deletions(-) rename src/{PaymentGateway.php => CheckoutGateway.php} (81%) create mode 100644 src/CheckoutRequest.php create mode 100644 src/CheckoutResponse.php rename src/{PaymentServiceProvider.php => CheckoutServiceProvider.php} (88%) rename src/{PaymentStatus.php => CheckoutStatus.php} (76%) rename src/Contracts/{PaymentRequestor.php => CheckoutRequester.php} (80%) rename src/Contracts/{PaymentResponder.php => CheckoutResponder.php} (97%) create mode 100644 src/Facades/Checkout.php delete mode 100644 src/Facades/Payment.php delete mode 100644 src/PaymentRequest.php delete mode 100644 src/PaymentResponse.php rename src/Traits/{PaymentRequests.php => CheckoutRequests.php} (84%) rename src/Traits/{PaymentResponses.php => CheckoutResponses.php} (99%) diff --git a/composer.json b/composer.json index ba757d3..4341fe9 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "payavel/checkout", - "description": "The best checkout solution that integrates with any payment processor and Laravel.", + "description": "Laravel package providing checkout with easy setup and flexible configurations to fit any e-commerce requirements.", "license": "MIT", "authors": [ { @@ -33,7 +33,7 @@ "extra": { "laravel": { "providers": [ - "Payavel\\Checkout\\PaymentServiceProvider" + "Payavel\\Checkout\\CheckoutServiceProvider" ] } } diff --git a/config/checkout.php b/config/checkout.php index 7bbb233..f774491 100644 --- a/config/checkout.php +++ b/config/checkout.php @@ -9,23 +9,23 @@ | Checkout Test Mode |-------------------------------------------------------------------------- | - | When set to true, the provider & account will be shared with the fake payment + | When set to true, the provider & account will be shared with the fake checkout | request so you can mock your responses as you wish. This is very useful for | local & testing environments where a sandbox is limited or non-existent. | */ - 'test_mode' => env('PAYMENT_TEST_MODE', false), + 'test_mode' => env('CHECKOUT_TEST_MODE', false), /* |-------------------------------------------------------------------------- | Checkout Testing |-------------------------------------------------------------------------- | - | This option allows you to define the location of the fake payment + | This option allows you to define the location of the fake checkout | request & response classes you would like to leverage when test_mode | is set to true. Also, feel free to add any other settings here. | */ - 'test_gateway' => \App\Services\Payment\FakePaymentRequest::class, + 'test_gateway' => \App\Services\Checkout\FakeCheckoutRequest::class, ]; diff --git a/database/factories/PaymentMethodFactory.php b/database/factories/PaymentMethodFactory.php index cef80ee..d1f078f 100644 --- a/database/factories/PaymentMethodFactory.php +++ b/database/factories/PaymentMethodFactory.php @@ -6,7 +6,6 @@ use Payavel\Checkout\Models\Wallet; use Payavel\Checkout\Models\PaymentMethod; use Payavel\Checkout\Models\PaymentType; -use Payavel\Orchestration\Support\ServiceConfig; class PaymentMethodFactory extends Factory { diff --git a/database/factories/PaymentTransactionEventFactory.php b/database/factories/PaymentTransactionEventFactory.php index 7c1d3ee..275b072 100644 --- a/database/factories/PaymentTransactionEventFactory.php +++ b/database/factories/PaymentTransactionEventFactory.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Factories\Factory; use Payavel\Checkout\Models\PaymentTransaction; use Payavel\Checkout\Models\PaymentTransactionEvent; -use Payavel\Checkout\PaymentStatus; +use Payavel\Checkout\CheckoutStatus; class PaymentTransactionEventFactory extends Factory { @@ -26,11 +26,11 @@ public function definition() return [ 'reference' => $this->faker->uuid(), 'status_code' => $this->faker->randomElement([ - PaymentStatus::CAPTURED, - PaymentStatus::SETTLED, - PaymentStatus::VOIDED, - PaymentStatus::REFUNDED, - PaymentStatus::REFUND_SETTLED, + CheckoutStatus::CAPTURED, + CheckoutStatus::SETTLED, + CheckoutStatus::VOIDED, + CheckoutStatus::REFUNDED, + CheckoutStatus::REFUND_SETTLED, ]), ]; } diff --git a/database/factories/PaymentTransactionFactory.php b/database/factories/PaymentTransactionFactory.php index bbddd54..152b2c2 100644 --- a/database/factories/PaymentTransactionFactory.php +++ b/database/factories/PaymentTransactionFactory.php @@ -4,7 +4,7 @@ use Illuminate\Database\Eloquent\Factories\Factory; use Payavel\Checkout\Models\PaymentTransaction; -use Payavel\Checkout\PaymentStatus; +use Payavel\Checkout\CheckoutStatus; use Payavel\Orchestration\Models\Account; use Payavel\Orchestration\Models\Provider; @@ -28,7 +28,7 @@ public function definition() 'reference' => $this->faker->uuid(), 'amount' => $this->faker->numberBetween(1, 999) * 100, 'currency' => $this->faker->currencyCode(), - 'status_code' => PaymentStatus::AUTHORIZED, + 'status_code' => CheckoutStatus::AUTHORIZED, ]; } diff --git a/src/PaymentGateway.php b/src/CheckoutGateway.php similarity index 81% rename from src/PaymentGateway.php rename to src/CheckoutGateway.php index 4984053..61d93d6 100644 --- a/src/PaymentGateway.php +++ b/src/CheckoutGateway.php @@ -4,7 +4,7 @@ use Payavel\Orchestration\Service; -class PaymentGateway extends Service +class CheckoutGateway extends Service { public function __construct() { diff --git a/src/CheckoutRequest.php b/src/CheckoutRequest.php new file mode 100644 index 0000000..8f2d638 --- /dev/null +++ b/src/CheckoutRequest.php @@ -0,0 +1,19 @@ +getStatusCode()); + } + + /** + * Get a description of the response's status. + * + * @return string|null + */ + public function getStatusDescription() + { + return CheckoutStatus::getMessage($this->getStatusCode()); + } +} diff --git a/src/PaymentServiceProvider.php b/src/CheckoutServiceProvider.php similarity index 88% rename from src/PaymentServiceProvider.php rename to src/CheckoutServiceProvider.php index 5417589..39b632a 100644 --- a/src/PaymentServiceProvider.php +++ b/src/CheckoutServiceProvider.php @@ -6,7 +6,7 @@ use Payavel\Checkout\Console\Commands\CheckoutInstall; use Payavel\Checkout\Console\Commands\CheckoutProvider; -class PaymentServiceProvider extends ServiceProvider +class CheckoutServiceProvider extends ServiceProvider { public function boot() { @@ -23,8 +23,8 @@ public function boot() public function register() { - $this->app->singleton(PaymentGateway::class, function ($app) { - return new PaymentGateway(); + $this->app->singleton(CheckoutGateway::class, function ($app) { + return new CheckoutGateway(); }); $this->mergeConfigFrom( diff --git a/src/PaymentStatus.php b/src/CheckoutStatus.php similarity index 76% rename from src/PaymentStatus.php rename to src/CheckoutStatus.php index 2b9fd03..9de4acb 100644 --- a/src/PaymentStatus.php +++ b/src/CheckoutStatus.php @@ -2,63 +2,63 @@ namespace Payavel\Checkout; -class PaymentStatus +class CheckoutStatus { - const AUTHORIZED = 200; - const APPROVED = 201; - const CAPTURED = 202; - const PARTIALLY_CAPTURED = 203; - const SETTLED = 204; - const CANCELED = 210; - const VOIDED = 211; - const REFUNDED = 212; - const PARTIALLY_REFUNDED = 213; - const REFUND_SETTLED = 214; - const REFUND_FAILED = 215; - const REFUND_REVERSED = 216; - const CHARGEBACK = 220; - const CHARGEBACK_WON = 221; - const CHARGEBACK_LOST = 222; - const CHARGEBACK_REVERSED = 223; - const SECOND_CHARGEBACK = 224; - const PENDING = 300; - const PROCESSING_ASYNC = 301; - const REFUSED = 400; - const DECLINED = 401; - const REFERRED = 402; - const NOT_ENOUGH_BALANCE = 403; - const INVALID_CARD = 410; - const INVALID_CARD_HOLDER_NAME = 411; - const INVALID_CARD_NUMBER = 412; - const INVALID_CARD_EXPIRY = 413; - const INVALID_CARD_SECURITY_CODE = 414; - const BLOCKED_CARD = 415; - const RESTRICTED_CARD = 416; - const INVALID_ADDRESS = 460; - const INVALID_BILLING_ADDRESS = 461; - const INVALID_SHIPPING_ADDRESS = 462; - const FRAUD = 470; - const FAILED_FRAUD_CHECK = 471; - const ACQUIRER_SUSPECTED_FRAUD = 472; - const ISSUER_SUSPECTED_FRAUD = 473; - const AVS_DECLINED = 474; - const INVALID_TRANSACTION = 480; - const INVALID_CREDENTIALS = 481; - const INVALID_AMOUNT = 482; - const TRANSACTION_NOT_SUPPORTED = 483; - const TRANSACTION_NOT_PERMITTED = 484; - const DUPLICATE_TRANSACTION = 485; - const PROCESSING_ISSUE = 490; - const AUTHORIZATION_REVOKED = 491; - const ACQUIRER_UNREACHABLE = 492; - const ISSUER_UNREACHABLE = 493; - const ERROR = 500; - const ACQUIRER_ERROR = 501; - const ISSUER_ERROR = 502; - const UNKNOWN_ERROR = 503; + public const AUTHORIZED = 200; + public const APPROVED = 201; + public const CAPTURED = 202; + public const PARTIALLY_CAPTURED = 203; + public const SETTLED = 204; + public const CANCELED = 210; + public const VOIDED = 211; + public const REFUNDED = 212; + public const PARTIALLY_REFUNDED = 213; + public const REFUND_SETTLED = 214; + public const REFUND_FAILED = 215; + public const REFUND_REVERSED = 216; + public const CHARGEBACK = 220; + public const CHARGEBACK_WON = 221; + public const CHARGEBACK_LOST = 222; + public const CHARGEBACK_REVERSED = 223; + public const SECOND_CHARGEBACK = 224; + public const PENDING = 300; + public const PROCESSING_ASYNC = 301; + public const REFUSED = 400; + public const DECLINED = 401; + public const REFERRED = 402; + public const NOT_ENOUGH_BALANCE = 403; + public const INVALID_CARD = 410; + public const INVALID_CARD_HOLDER_NAME = 411; + public const INVALID_CARD_NUMBER = 412; + public const INVALID_CARD_EXPIRY = 413; + public const INVALID_CARD_SECURITY_CODE = 414; + public const BLOCKED_CARD = 415; + public const RESTRICTED_CARD = 416; + public const INVALID_ADDRESS = 460; + public const INVALID_BILLING_ADDRESS = 461; + public const INVALID_SHIPPING_ADDRESS = 462; + public const FRAUD = 470; + public const FAILED_FRAUD_CHECK = 471; + public const ACQUIRER_SUSPECTED_FRAUD = 472; + public const ISSUER_SUSPECTED_FRAUD = 473; + public const AVS_DECLINED = 474; + public const INVALID_TRANSACTION = 480; + public const INVALID_CREDENTIALS = 481; + public const INVALID_AMOUNT = 482; + public const TRANSACTION_NOT_SUPPORTED = 483; + public const TRANSACTION_NOT_PERMITTED = 484; + public const DUPLICATE_TRANSACTION = 485; + public const PROCESSING_ISSUE = 490; + public const AUTHORIZATION_REVOKED = 491; + public const ACQUIRER_UNREACHABLE = 492; + public const ISSUER_UNREACHABLE = 493; + public const ERROR = 500; + public const ACQUIRER_ERROR = 501; + public const ISSUER_ERROR = 502; + public const UNKNOWN_ERROR = 503; /** - * List of all supported payment response codes. + * List of all supported checkout response codes. * * @var array */ @@ -118,7 +118,7 @@ class PaymentStatus ]; /** - * List of all supported payment response code messages. + * List of all supported checkout response code messages. * * @var array */ diff --git a/src/Contracts/PaymentRequestor.php b/src/Contracts/CheckoutRequester.php similarity index 80% rename from src/Contracts/PaymentRequestor.php rename to src/Contracts/CheckoutRequester.php index 1a93588..ff3cd6d 100644 --- a/src/Contracts/PaymentRequestor.php +++ b/src/Contracts/CheckoutRequester.php @@ -7,65 +7,65 @@ use Payavel\Checkout\Models\PaymentTransaction; use Payavel\Checkout\Models\Wallet; -interface PaymentRequestor +interface CheckoutRequester { /** * Retrieve the wallet's details from the provider. * * @param \Payavel\Checkout\Models\Wallet $wallet - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function getWallet(Wallet $wallet); /** * Retrieve the payment method's details from the provider. - * + * * @param \Payavel\Checkout\Models\PaymentMethod $paymentMethod - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function getPaymentMethod(PaymentMethod $paymentMethod); /** * Store the payment method details at the provider. - * + * * @param \Payavel\Checkout\Contracts\Billable $billable * @param array|mixed $data - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function tokenizePaymentMethod(Billable $billable, $data); /** * Update the payment method's details at the provider. - * + * * @param \Payavel\Checkout\Models\PaymentMethod $paymentMethod * @param array|mixed $data - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function updatePaymentMethod(PaymentMethod $paymentMethod, $data); - + /** * Delete the payment method at the provider. - * + * * @param \Payavel\Checkout\Models\PaymentMethod $paymentMethod - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function deletePaymentMethod(PaymentMethod $paymentMethod); /** * Authorize a transaction. - * + * * @param array|mixed $data * @param \Payavel\Checkout\Contracts\Billable|null $billable - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function authorize($data, Billable $billable = null); /** * Capture a previously authorized transaction. - * + * * @param \Payavel\Checkout\Models\PaymentTransaction $transaction * @param array|mixed $data - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function capture(PaymentTransaction $transaction, $data = []); @@ -73,25 +73,25 @@ public function capture(PaymentTransaction $transaction, $data = []); * Retrieve the transaction details from the provider. * * @param \Payavel\Checkout\Models\PaymentTransaction $transaction - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function getTransaction(PaymentTransaction $transaction); /** * Void a previously authorized transaction. - * + * * @param \Payavel\Checkout\Models\PaymentTransaction $transaction * @param array|mixed $data - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function void(PaymentTransaction $transaction, $data = []); /** * Refund a previously captured transaction. - * + * * @param \Payavel\Checkout\Models\PaymentTransaction $transaction * @param array|mixed - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function refund(PaymentTransaction $transaction, $data = []); } diff --git a/src/Contracts/PaymentResponder.php b/src/Contracts/CheckoutResponder.php similarity index 97% rename from src/Contracts/PaymentResponder.php rename to src/Contracts/CheckoutResponder.php index d7b4dd5..fe6e2c6 100644 --- a/src/Contracts/PaymentResponder.php +++ b/src/Contracts/CheckoutResponder.php @@ -2,7 +2,7 @@ namespace Payavel\Checkout\Contracts; -interface PaymentResponder +interface CheckoutResponder { /** * Maps details from the getWallet() response to the expected format. @@ -31,7 +31,7 @@ public function tokenizePaymentMethodResponse(); * @return array|mixed */ public function updatePaymentMethodResponse(); - + /** * Maps details from the deletePaymentMethod() response to the expected format. * @@ -55,7 +55,7 @@ public function captureResponse(); /** * Maps details from the getTransaction() response to the expected format. - * + * * @return array|mixed */ public function getTransactionResponse(); diff --git a/src/Facades/Checkout.php b/src/Facades/Checkout.php new file mode 100644 index 0000000..7eb583f --- /dev/null +++ b/src/Facades/Checkout.php @@ -0,0 +1,42 @@ +paymentGateway)) { - $this->paymentGateway = (new PaymentGateway()) + $this->paymentGateway = (new CheckoutGateway()) ->provider($this->provider) ->account($this->account); } diff --git a/src/Models/Traits/PaymentMethodRequests.php b/src/Models/Traits/PaymentMethodRequests.php index 1f4e729..827db46 100644 --- a/src/Models/Traits/PaymentMethodRequests.php +++ b/src/Models/Traits/PaymentMethodRequests.php @@ -9,7 +9,7 @@ trait PaymentMethodRequests /** * Fetch the payment method details from the provider. * - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function fetch() { @@ -20,7 +20,7 @@ public function fetch() * Request the provider to update the payment method's details. * * @param array|mixed $data - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function patch($data) { @@ -30,7 +30,7 @@ public function patch($data) /** * Request the provider to remove the payment method from their system. * - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function disable() { diff --git a/src/Models/Traits/PaymentTransactionRequests.php b/src/Models/Traits/PaymentTransactionRequests.php index 10081af..bb97a2f 100644 --- a/src/Models/Traits/PaymentTransactionRequests.php +++ b/src/Models/Traits/PaymentTransactionRequests.php @@ -9,7 +9,7 @@ trait PaymentTransactionRequests /** * Fetch the transaction details from the provider. * - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function fetch() { @@ -20,7 +20,7 @@ public function fetch() * Request the provider to void the transaction. * * @param array|mixed $data - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function void($data = []) { @@ -31,7 +31,7 @@ public function void($data = []) * Request the provider to refund the transaction. * * @param array|mixed $data - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function refund($data = []) { diff --git a/src/Models/Traits/WalletRequests.php b/src/Models/Traits/WalletRequests.php index 1be657f..04246f5 100644 --- a/src/Models/Traits/WalletRequests.php +++ b/src/Models/Traits/WalletRequests.php @@ -9,7 +9,7 @@ trait WalletRequests /** * Fetch the wallet details from the provider. * - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function fetch() { diff --git a/src/PaymentRequest.php b/src/PaymentRequest.php deleted file mode 100644 index 0970057..0000000 --- a/src/PaymentRequest.php +++ /dev/null @@ -1,19 +0,0 @@ -getStatusCode()); - } - - /** - * Get a description of the response's status. - * - * @return string|null - */ - public function getStatusDescription() - { - return PaymentStatus::getMessage($this->getStatusCode()); - } -} diff --git a/src/Traits/PaymentRequests.php b/src/Traits/CheckoutRequests.php similarity index 84% rename from src/Traits/PaymentRequests.php rename to src/Traits/CheckoutRequests.php index 3a074cb..7d859e3 100644 --- a/src/Traits/PaymentRequests.php +++ b/src/Traits/CheckoutRequests.php @@ -8,7 +8,7 @@ use Payavel\Checkout\Models\Wallet; use Payavel\Orchestration\Traits\ThrowsRuntimeException; -trait PaymentRequests +trait CheckoutRequests { use ThrowsRuntimeException; @@ -16,7 +16,7 @@ trait PaymentRequests * Retrieve the wallet's details from the provider. * * @param \Payavel\Checkout\Models\Wallet $wallet - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function getWallet(Wallet $wallet) { @@ -25,9 +25,9 @@ public function getWallet(Wallet $wallet) /** * Retrieve the payment method's details from the provider. - * + * * @param \Payavel\Checkout\Models\PaymentMethod $paymentMethod - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function getPaymentMethod(PaymentMethod $paymentMethod) { @@ -36,10 +36,10 @@ public function getPaymentMethod(PaymentMethod $paymentMethod) /** * Store the payment method details at the provider. - * + * * @param \Payavel\Checkout\Contracts\Billable $billable * @param array|mixed $data - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function tokenizePaymentMethod(Billable $billable, $data) { @@ -48,21 +48,21 @@ public function tokenizePaymentMethod(Billable $billable, $data) /** * Update the payment method's details at the provider. - * + * * @param \Payavel\Checkout\Models\PaymentMethod $paymentMethod * @param array|mixed $data - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function updatePaymentMethod(PaymentMethod $paymentMethod, $data) { $this->throwRuntimeException(__FUNCTION__); } - + /** * Delete the payment method at the provider. - * + * * @param \Payavel\Checkout\Models\PaymentMethod $paymentMethod - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function deletePaymentMethod(PaymentMethod $paymentMethod) { @@ -71,10 +71,10 @@ public function deletePaymentMethod(PaymentMethod $paymentMethod) /** * Authorize a transaction. - * + * * @param array|mixed $data * @param \Payavel\Checkout\Contracts\Billable|null $billable - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function authorize($data, Billable $billable = null) { @@ -83,10 +83,10 @@ public function authorize($data, Billable $billable = null) /** * Capture a previously authorized transaction. - * + * * @param \Payavel\Checkout\Models\PaymentTransaction $transaction * @param array|mixed $data - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function capture(PaymentTransaction $transaction, $data = []) { @@ -97,7 +97,7 @@ public function capture(PaymentTransaction $transaction, $data = []) * Retrieve the transaction details from the provider. * * @param \Payavel\Checkout\Models\PaymentTransaction $transaction - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function getTransaction(PaymentTransaction $transaction) { @@ -106,10 +106,10 @@ public function getTransaction(PaymentTransaction $transaction) /** * Void a previously authorized transaction. - * + * * @param \Payavel\Checkout\Models\PaymentTransaction $paymentTransaction * @param array|mixed $data - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function void(PaymentTransaction $paymentTransaction, $data = []) { @@ -118,10 +118,10 @@ public function void(PaymentTransaction $paymentTransaction, $data = []) /** * Refund a previously captured transaction. - * + * * @param \Payavel\Checkout\Models\PaymentTransaction $paymentTransaction * @param array|mixed $data - * @return \Payavel\Checkout\PaymentResponse + * @return \Payavel\Checkout\CheckoutResponse */ public function refund(PaymentTransaction $paymentTransaction, $data = []) { diff --git a/src/Traits/PaymentResponses.php b/src/Traits/CheckoutResponses.php similarity index 99% rename from src/Traits/PaymentResponses.php rename to src/Traits/CheckoutResponses.php index 955bb55..80fc9ce 100644 --- a/src/Traits/PaymentResponses.php +++ b/src/Traits/CheckoutResponses.php @@ -6,7 +6,7 @@ use Payavel\Orchestration\Traits\ThrowsRuntimeException; use RuntimeException; -trait PaymentResponses +trait CheckoutResponses { use ThrowsRuntimeException; @@ -96,7 +96,7 @@ public function captureResponse() /** * Maps details from the getTransaction() response to the expected format. - * + * * @return array|mixed */ public function getTransactionResponse() diff --git a/tests/TestCase.php b/tests/TestCase.php index d9058ef..7ff13c2 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,7 +3,7 @@ namespace Payavel\Checkout\Tests; use Payavel\Checkout\Contracts\Billable; -use Payavel\Checkout\PaymentServiceProvider; +use Payavel\Checkout\CheckoutServiceProvider; use Payavel\Checkout\Traits\Billable as BillableTrait; use Payavel\Orchestration\Contracts\Serviceable; use Payavel\Orchestration\OrchestrationServiceProvider; @@ -19,7 +19,7 @@ protected function getPackageProviders($app) { return [ OrchestrationServiceProvider::class, - PaymentServiceProvider::class, + CheckoutServiceProvider::class, ]; } diff --git a/tests/Unit/TestCheckoutGateway.php b/tests/Unit/TestCheckoutGateway.php index 551847e..9a4e894 100644 --- a/tests/Unit/TestCheckoutGateway.php +++ b/tests/Unit/TestCheckoutGateway.php @@ -3,13 +3,13 @@ namespace Payavel\Checkout\Tests\Unit; use Payavel\Checkout\Contracts\Billable; -use Payavel\Checkout\Facades\Payment; +use Payavel\Checkout\Facades\Checkout; use Payavel\Checkout\Models\PaymentMethod; use Payavel\Checkout\Models\PaymentTransaction; use Payavel\Checkout\Models\Wallet; -use Payavel\Checkout\PaymentRequest; -use Payavel\Checkout\PaymentResponse; -use Payavel\Checkout\PaymentStatus; +use Payavel\Checkout\CheckoutRequest; +use Payavel\Checkout\CheckoutResponse; +use Payavel\Checkout\CheckoutStatus; use Payavel\Checkout\Tests\TestCase; use Payavel\Checkout\Tests\User; use Payavel\Orchestration\Tests\Contracts\CreatesServiceables; @@ -41,11 +41,11 @@ protected function setUp(): void public function get_wallet_method_returns_configured_response() { $wallet = Wallet::factory()->create([ - 'provider_id' => Payment::getProvider()->getId(), - 'account_id' => Payment::getAccount()->getId(), + 'provider_id' => Checkout::getProvider()->getId(), + 'account_id' => Checkout::getAccount()->getId(), ]); - $response = Payment::getWallet($wallet); + $response = Checkout::getWallet($wallet); $this->assertResponseIsConfigured($response); @@ -56,15 +56,15 @@ public function get_wallet_method_returns_configured_response() public function get_payment_method_method_returns_configured_response() { $wallet = Wallet::factory()->create([ - 'provider_id' => Payment::getProvider()->getId(), - 'account_id' => Payment::getAccount()->getId(), + 'provider_id' => Checkout::getProvider()->getId(), + 'account_id' => Checkout::getAccount()->getId(), ]); $paymentMethod = PaymentMethod::factory()->create([ 'wallet_id' => $wallet->id, ]); - $response = Payment::getPaymentMethod($paymentMethod); + $response = Checkout::getPaymentMethod($paymentMethod); $this->assertResponseIsConfigured($response); @@ -76,7 +76,7 @@ public function tokenize_payment_method_method_returns_configured_response() { $user = User::factory()->create(); - $response = Payment::tokenizePaymentMethod($user, []); + $response = Checkout::tokenizePaymentMethod($user, []); $this->assertResponseIsConfigured($response); @@ -87,15 +87,15 @@ public function tokenize_payment_method_method_returns_configured_response() public function update_payment_method_method_returns_configured_response() { $wallet = Wallet::factory()->create([ - 'provider_id' => Payment::getProvider()->getId(), - 'account_id' => Payment::getAccount()->getId(), + 'provider_id' => Checkout::getProvider()->getId(), + 'account_id' => Checkout::getAccount()->getId(), ]); $paymentMethod = PaymentMethod::factory()->create([ 'wallet_id' => $wallet->id, ]); - $response = Payment::updatePaymentMethod($paymentMethod, []); + $response = Checkout::updatePaymentMethod($paymentMethod, []); $this->assertResponseIsConfigured($response); @@ -106,15 +106,15 @@ public function update_payment_method_method_returns_configured_response() public function delete_payment_method_method_returns_configured_response() { $wallet = Wallet::factory()->create([ - 'provider_id' => Payment::getProvider()->getId(), - 'account_id' => Payment::getAccount()->getId(), + 'provider_id' => Checkout::getProvider()->getId(), + 'account_id' => Checkout::getAccount()->getId(), ]); $paymentMethod = PaymentMethod::factory()->create([ 'wallet_id' => $wallet->id, ]); - $response = Payment::deletePaymentMethod($paymentMethod); + $response = Checkout::deletePaymentMethod($paymentMethod); $this->assertResponseIsConfigured($response); @@ -124,7 +124,7 @@ public function delete_payment_method_method_returns_configured_response() #[Test] public function authorize_method_returns_configured_response() { - $response = Payment::authorize([]); + $response = Checkout::authorize([]); $this->assertResponseIsConfigured($response); @@ -135,11 +135,11 @@ public function authorize_method_returns_configured_response() public function capture_method_returns_configured_response() { $transaction = PaymentTransaction::factory()->create([ - 'provider_id' => Payment::getProvider()->getId(), - 'account_id' => Payment::getAccount()->getId(), + 'provider_id' => Checkout::getProvider()->getId(), + 'account_id' => Checkout::getAccount()->getId(), ]); - $response = Payment::capture($transaction); + $response = Checkout::capture($transaction); $this->assertResponseIsConfigured($response); @@ -150,11 +150,11 @@ public function capture_method_returns_configured_response() public function get_transaction_method_returns_configured_response() { $transaction = PaymentTransaction::factory()->create([ - 'provider_id' => Payment::getProvider()->getId(), - 'account_id' => Payment::getAccount()->getId(), + 'provider_id' => Checkout::getProvider()->getId(), + 'account_id' => Checkout::getAccount()->getId(), ]); - $response = Payment::getTransaction($transaction); + $response = Checkout::getTransaction($transaction); $this->assertResponseIsConfigured($response); @@ -165,11 +165,11 @@ public function get_transaction_method_returns_configured_response() public function void_method_returns_configured_response() { $transaction = PaymentTransaction::factory()->create([ - 'provider_id' => Payment::getProvider()->getId(), - 'account_id' => Payment::getAccount()->getId(), + 'provider_id' => Checkout::getProvider()->getId(), + 'account_id' => Checkout::getAccount()->getId(), ]); - $response = Payment::void($transaction); + $response = Checkout::void($transaction); $this->assertResponseIsConfigured($response); @@ -180,11 +180,11 @@ public function void_method_returns_configured_response() public function refund_method_returns_configured_response() { $transaction = PaymentTransaction::factory()->create([ - 'provider_id' => Payment::getProvider()->getId(), - 'account_id' => Payment::getAccount()->getId(), + 'provider_id' => Checkout::getProvider()->getId(), + 'account_id' => Checkout::getAccount()->getId(), ]); - $response = Payment::refund($transaction); + $response = Checkout::refund($transaction); $this->assertResponseIsConfigured($response); @@ -195,17 +195,17 @@ public function refund_method_returns_configured_response() * Assert the response is configured automatically. * * @param string $requestMethod - * @param \Payavel\Checkout\PaymentResponse $response + * @param \Payavel\Checkout\CheckoutResponse $response * @return void */ - protected function assertResponseIsConfigured(PaymentResponse $response) + protected function assertResponseIsConfigured(CheckoutResponse $response) { - $this->assertEquals(Payment::getProvider()->getId(), $response->provider->id); - $this->assertEquals(Payment::getAccount()->getId(), $response->account->id); + $this->assertEquals(Checkout::getProvider()->getId(), $response->provider->id); + $this->assertEquals(Checkout::getAccount()->getId(), $response->account->id); } } -class TestPaymentRequest extends PaymentRequest +class TestPaymentRequest extends CheckoutRequest { public function getWallet(Wallet $wallet) { @@ -258,7 +258,7 @@ public function refund(PaymentTransaction $paymentTransaction, $data = []) } } -class TestPaymentResponse extends PaymentResponse +class TestPaymentResponse extends CheckoutResponse { public function getWalletResponse() { @@ -332,6 +332,6 @@ public function refundResponse() public function getStatusCode() { - return PaymentStatus::AUTHORIZED; + return CheckoutStatus::AUTHORIZED; } }