Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Add ability to reset() payment service. #33

Merged
merged 3 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Facades/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @method static \Payavel\Checkout\PaymentGateway merchant($merchant)
* @method static \Payavel\Checkout\Contracts\Merchantable getMerchant()
* @method static void setMerchant($merchant, $strict = true)
* @method static void reset()
* @method static string|int|\Payavel\Checkout\Contracts\Merchantable getDefaultMerchant()
* @method static \Payavel\Checkout\PaymentResponse getWallet(\Payavel\Checkout\Models\Wallet $wallet)
* @method static \Payavel\Checkout\PaymentResponse getPaymentMethod(\Payavel\Checkout\Models\PaymentMethod $paymentMethod)
Expand Down
12 changes: 12 additions & 0 deletions src/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,16 @@ protected function setGateway()

$this->gateway = new $gateway($provider, $merchant);
}

/**
* Reset the payment service to it's defaults.
*
* @return void
*/
public function reset()
{
$this->provider = null;
$this->merchant = null;
$this->gateway = null;
}
}
2 changes: 1 addition & 1 deletion tests/GatewayTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class AlternativePaymentRequest extends PaymentRequest
{
public function authorize($data, Billable $billable = null)
{
return new TestPaymentResponse([]);
return new AlternativePaymentResponse([]);
}
}

Expand Down
20 changes: 17 additions & 3 deletions tests/Unit/TestPaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use Payavel\Checkout\Models\PaymentTransaction;
use Payavel\Checkout\Models\Wallet;
use Payavel\Checkout\PaymentResponse;
use Payavel\Checkout\Tests\AlternativePaymentResponse;
use Payavel\Checkout\Tests\GatewayTestCase;
use Payavel\Checkout\Tests\TestPaymentResponse;
use Payavel\Checkout\Tests\User;

class TestPaymentGateway extends GatewayTestCase
Expand All @@ -24,7 +26,7 @@ public function set_provider_and_merchant_fluently()
/** @test */
public function setting_invalid_driver_throws_exception()
{
config(['payment.defaults.driver' => 'fake']);
config(['payment.defaults.driver' => 'invalid']);

$this->expectException(Exception::class);
$this->expectExceptionMessage('Invalid checkout driver provided.');
Expand All @@ -38,7 +40,7 @@ public function setting_invalid_provider_throws_exception()
$this->expectException(Exception::class);
$this->expectExceptionMessage('Invalid checkout provider.');

Payment::setProvider('fake');
Payment::setProvider('invalid');
}

/** @test */
Expand All @@ -47,7 +49,7 @@ public function setting_invalid_merchant_throws_exception()
$this->expectException(Exception::class);
$this->expectExceptionMessage('Invalid checkout merchant.');

Payment::setMerchant('faker');
Payment::setMerchant('invalid');
}

/** @test */
Expand All @@ -60,6 +62,18 @@ public function setting_incompatible_merchant_provider_throws_exception()
Payment::authorize([]);
}

/** @test */
public function resetting_payment_service_to_default_configuration()
{
Payment::provider('alternative')->merchant('alternate');

$this->assertEquals(AlternativePaymentResponse::class, get_class(Payment::authorize([])));

Payment::reset();

$this->assertEquals(TestPaymentResponse::class, get_class(Payment::authorize([])));
}

/** @test */
public function payment_service_throws_exception_when_test_mode_gateway_does_not_exist()
{
Expand Down