Skip to content

Commit

Permalink
Redirect customer to next step in invest controller
Browse files Browse the repository at this point in the history
  • Loading branch information
subiabre committed Nov 24, 2023
1 parent 2f748c6 commit 4e3cc4f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
17 changes: 14 additions & 3 deletions src/Goteo/Payment/Method/StripeSubscriptionPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@ public function isPublic($amount = 0): bool
return true;
}

public function purchase(): ResponseInterface
public function getGateway(): SubscriptionGateway
{
$gateway = Omnipay::create(SubscriptionGateway::class);
return Omnipay::create(SubscriptionGateway::class);
}

$response = $gateway->purchase([
public function purchase(): ResponseInterface
{
$response = $this->getGateway()->purchase([
'invest' => $this->invest,
'user' => $this->user
])->send();
Expand All @@ -78,6 +81,14 @@ public function purchase(): ResponseInterface
return $response;
}

public function completePurchase(): ResponseInterface
{
/** @var SubscriptionGateway */
$gateway = $this->getGateway();

return $gateway->completePurchase(['success' => true]);
}

public function refundable(): bool
{
return false;
Expand Down
8 changes: 8 additions & 0 deletions src/Omnipay/Stripe/Subscription/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Omnipay\Common\AbstractGateway;
use Omnipay\Common\Http\ClientInterface;
use Omnipay\Stripe\Subscription\Message\SubscriptionRequest;
use Omnipay\Stripe\Subscription\Message\SubscriptionResponse;
use Symfony\Component\HttpFoundation\Request as HttpRequest;

class Gateway extends AbstractGateway
Expand All @@ -29,4 +30,11 @@ public function purchase($options = array())
{
return new SubscriptionRequest($options);
}

public function completePurchase($options = array()): SubscriptionResponse
{
$request = new SubscriptionRequest($options);

return $request->completePurchase($options);
}
}
13 changes: 9 additions & 4 deletions src/Omnipay/Stripe/Subscription/Message/SubscriptionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function sendData($data)

$session = $this->stripe->checkout->sessions->create([
'customer' => $this->getStripeCustomer($data['user'])->id,
'success_url' => $this->getRedirectUrl('/dashboard/subscriptions'),
'cancel_url' => $this->getRedirectUrl('/project/', $data['invest']->getProject()->id),
'success_url' => $this->getRedirectUrl('invest', $data['invest']->getProject()->id, $data['invest']->id, 'complete'),
'cancel_url' => $this->getRedirectUrl('project', $data['invest']->getProject()->id),
'mode' => 'subscription',
'line_items' => [
[
Expand All @@ -55,13 +55,18 @@ public function sendData($data)
return new SubscriptionResponse($this, $session);
}

public function completePurchase(array $options = [])
{
return new SubscriptionResponse($this, $options);
}

private function getRedirectUrl(...$args): string
{
return sprintf(
'%s://%s%s',
'%s://%s/%s',
isset($_SERVER['HTTPS']) ? 'https' : 'http',
$_SERVER['HTTP_HOST'],
implode('', $args)
implode('/', $args)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SubscriptionResponse extends AbstractResponse implements RedirectResponseI
{
public function isSuccessful()
{
return false;
return $this->data['success'];
}

public function isRedirect()
Expand Down

0 comments on commit 4e3cc4f

Please sign in to comment.