Skip to content

Commit

Permalink
Merge branch 'feature/stripe_integration' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbeig committed Nov 24, 2023
2 parents a697139 + 42299f5 commit b59e547
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 10 deletions.
13 changes: 11 additions & 2 deletions Resources/templates/responsive/invest/partials/reward_box.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
<?php
$matchedReward = $reward->isMatched();
?>
<label class="label-reward <?= $selected ? 'reward-choosen' : '' ?><?= $available ? '' : ' label-disabled' ?> <?= $matchedReward ? 'matched-reward' : ''?>" for="reward-<?= $reward->id ?>">

<label
class="label-reward
<?= $selected ? 'reward-choosen' : '' ?>
<?= $available ? '' : ' label-disabled' ?>
<?= $matchedReward ? 'matched-reward' : ''?>
<?= $reward->subscribable ? 'reward-subscribable' : '' ?>"
for="reward-<?= $reward->id ?>"
>
<?php if ($matchedReward): ?>
<div class="btn-lilac">
<i class="icon icon-call"></i> <?= $this->t('regular-call') ?>
Expand All @@ -32,6 +38,9 @@
<?= $this->markdown($reward->description) ?>
</div>
<div style="margin-top:10px">
<?php if ($reward->subscribable): ?>
<span class="subscription-reward"><?= $this->text('invest-reward-subscribable') ?></span>
<?php endif ?>
<?php if (!$available) : // no quedan ?>
<span class="limit-reward"><?= $this->text('invest-reward-none') ?></span>
<?php elseif (!empty($reward->units)) : // unidades limitadas ?>
Expand Down
8 changes: 8 additions & 0 deletions public/assets/sass/layouts/_invest.scss
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ body.invest {
display: inline-block;
}
}

&.reward-subscribable {
background-color: #76cfad;
}

&.reward-subscribable:hover {
background-color: #2cb2b2;
}
}
}

Expand Down
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
1 change: 1 addition & 0 deletions translations/ca/invest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ invest-process-completed: 'Aquesta aportació ja es va completar anteriorment'
invest-project: 'al projecte'
invest-resign: 'Renuncio a una recompensa individual, només vull donar suport al projecte'
invest-reward-first: 'Recorda que la quantitat a aportar ha de ser més gran que 0'
invest-reward-subscribable: 'Subscripció mensual'
invest-reward-none: 'Ja no es pot escollir'
invest-reward-not-found: 'Aquesta recompensa no existeis!'
invest-reward-used-up: 'Ja queden unitats d''aquesta recompensa!'
Expand Down
1 change: 1 addition & 0 deletions translations/en/invest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ invest-pool-method: 'Virtual Wallet'
invest-process-completed: 'Your contribution has been completed previoulsy'
invest-project: 'to the project'
invest-resign: 'I renounce to my personal reward, I just want to support the project'
invest-reward-subscribable: 'Monthly subscription'
invest-reward-none: 'These can no longer be chosen'
invest-reward-not-found: 'Reward not found!'
invest-reward-used-up: 'This reward has been used up!'
Expand Down
1 change: 1 addition & 0 deletions translations/es/invest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ invest-process-completed: 'Este aporte ya se completó anteriormente'
invest-project: 'al proyecto'
invest-resign: 'Renuncio a una recompensa individual, solo quiero ayudar al proyecto'
invest-reward-first: 'Recuerda que la cantidad a aportar debe ser mayor a 0'
invest-reward-subscribable: 'Suscripción mensual'
invest-reward-none: 'Ya no se puede elegir'
invest-reward-not-found: 'Esta recompensa no se ha encontrado!'
invest-reward-used-up: '¡Ya no quedan unidades de esta recompensa!'
Expand Down

0 comments on commit b59e547

Please sign in to comment.