Skip to content

Commit

Permalink
Added the return_url configuration
Browse files Browse the repository at this point in the history
- Passing it in the `$options` array is no longer needed
  • Loading branch information
fulopattila122 committed Jul 26, 2024
1 parent effdd12 commit dc052a7
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 20 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## 2.x

### Unreleased
#### 2024-XX-YY

- Added the `return_url` configuration (passing it in the `$options` array is no longer needed)

### 2.0.0
#### 2024-07-26

Expand Down
8 changes: 2 additions & 6 deletions src/Concerns/HasStripeConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
trait HasStripeConfiguration
{
use HasStripeCredentials;
//
//private string $returnUrl;
//
//private string $cancelUrl;
//
//private bool $isSandbox;

private ?string $returnUrl = null;
}
8 changes: 6 additions & 2 deletions src/Concerns/HasStripeInteraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ trait HasStripeInteraction
{
use HasStripeConfiguration;

public function __construct(string $secretKey, string $publicKey)
{
public function __construct(
string $secretKey,
string $publicKey,
?string $returnUrl = null,
) {
$this->secretKey = $secretKey;
$this->publicKey = $publicKey;
$this->returnUrl = $returnUrl;
}
}
7 changes: 2 additions & 5 deletions src/Factories/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ public function create(Payment $payment, array $options = []): StripePaymentRequ
->setPublicKey($this->publicKey)
->setPaymentId($payment->getPaymentId())
->setCurrency($payment->getCurrency())
->setAmount($payment->getAmount());

if (isset($options['return_url'])) {
$result->setReturnUrl($options['return_url']);
}
->setAmount($payment->getAmount())
->setReturnUrl($this->returnUrl);

if (isset($options['view'])) {
$result->setView($options['view']);
Expand Down
4 changes: 1 addition & 3 deletions src/Messages/StripePaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class StripePaymentRequest implements PaymentRequest

private float $amount;

private ?string $returnUrl = null;

private string $view = 'stripe::_request';

public function getHtmlSnippet(array $options = []): ?string
Expand Down Expand Up @@ -101,7 +99,7 @@ public function setView(string $view): self
return $this;
}

public function setReturnUrl(string $returnUrl): self
public function setReturnUrl(?string $returnUrl): self
{
$this->returnUrl = $returnUrl;

Expand Down
3 changes: 2 additions & 1 deletion src/Providers/ModuleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public function boot()
$this->app->bind(StripePaymentGateway::class, function ($app) {
return new StripePaymentGateway(
$this->config('secret_key'),
$this->config('public_key')
$this->config('public_key'),
$this->config('return_url'),
);
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/StripePaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public function createPaymentRequest(Payment $payment, Address $shippingAddress
if (null === $this->requestFactory) {
$this->requestFactory = new RequestFactory(
$this->secretKey,
$this->publicKey
$this->publicKey,
$this->returnUrl,
);
}

Expand Down
3 changes: 2 additions & 1 deletion src/resources/config/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
],
'bind' => true,
'secret_key' => env('STRIPE_SECRET_KEY', ''),
'public_key' => env('STRIPE_PUBLICK_KEY', ''),
'public_key' => env('STRIPE_PUBLIC_KEY', ''),
'return_url' => env('STRIPE_RETURN_URL', ''),
];
2 changes: 1 addition & 1 deletion tests/Factory/RequestFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RequestFactoryTest extends TestCase
/** @test */
public function it_creates_a_request_object()
{
$factory = new RequestFactory('secret', 'pkey');
$factory = new RequestFactory('secret', 'pkey', url('/'));
$method = PaymentMethod::create([
'gateway' => StripePaymentGateway::getName(),
'name' => 'Stripe',
Expand Down

0 comments on commit dc052a7

Please sign in to comment.