Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/stripe_integration' into…
Browse files Browse the repository at this point in the history
… feature/beta_stripe_integration
  • Loading branch information
davidbeig committed Nov 23, 2023
2 parents 9dd2ac3 + 2f748c6 commit fa3b68f
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 37 deletions.
14 changes: 14 additions & 0 deletions Resources/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,20 @@ payments:
# Other variables may be added on other methods and
# customize the calculateFee() in the corresponding class

# Stripe
stripe:
active: false
publicKey: pk_test_
secretKey: sk_test_
webhookSecret: whsec_
commissions:
refunded:
fixed: 0
percent: 0
charged:
fixed: 0.25
percent: 2

# This is a built-in payment method using internal credit
pool:
active: true
Expand Down
6 changes: 6 additions & 0 deletions Resources/roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ user: # This user is assigned automatically to all users regardless the user_rol
- remove-project # remove own project, this permission is implicit
level: 0 # Order of the role, roles with supperior level can do some actions over this

creator:
extends: user # inhertis permissions from role "user"
perms:
- highlight-project # can feature own projects in their creator profile
level: 10

vip:
extends: user # inherits permissions from role "user"
perms:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<td><?= $subscription['id'] ?></td>
</tr>
<tr>
<td>Creada</td>
<td><?= $this->t('subscription-data-start-date') ?></td>
<td><?= \date_formater(date('Y-m-d', $subscription['start_date'])) ?></td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion src/Goteo/Controller/StripeSubscriptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private function createInvest(string $invoiceId): Invest
'user' => $user->id,
'project' => explode('_', $subscription->items->data[0]->price->product)[0],
'method' => StripeSubscriptionPaymentMethod::PAYMENT_METHOD_ID,
'status' => Invest::STATUS_PAID,
'status' => Invest::STATUS_CHARGED,
'invested' => date('Y-m-d'),
]);

Expand Down
19 changes: 8 additions & 11 deletions src/Goteo/Library/Forms/Model/ProjectCampaignForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Goteo\Library\Forms\FormProcessorInterface;
use Goteo\Library\Forms\AbstractFormProcessor;
use Goteo\Library\Forms\FormModelException;
use Goteo\Model\Project;
use Goteo\Model\Project\Conf;
use Goteo\Util\Form\Type\BooleanType;
use Goteo\Util\Form\Type\ChoiceType;
Expand Down Expand Up @@ -63,6 +62,13 @@ public function createForm(): ProjectCampaignForm
],
'color' => 'cyan',
'required' => false
])
->add('allowStripe', BooleanType::class, [
'label' => Text::get('project-campaign-use-stripe'),
'data' => $account->allow_stripe,
'disabled' => $this->getReadonly(),
'required' => false,
'color' => 'cyan'
]);
}

Expand Down Expand Up @@ -96,13 +102,6 @@ public function createForm(): ProjectCampaignForm
'required' => false,
'color' => 'cyan',
])
->add('allowStripe', BooleanType::class, [
'label' => Text::get('project-campaign-use-stripe'),
'data' => $account->allow_stripe,
'disabled' => $this->getReadonly(),
'required' => false,
'color' => 'cyan'
])
->add('spread', TextareaType::class, [
'label' => 'overview-field-spread',
'disabled' => $this->getReadonly(),
Expand All @@ -112,9 +111,7 @@ public function createForm(): ProjectCampaignForm
'info' => '<i class="fa fa-eye-slash"></i> '. Text::get('project-non-public-field'),
'rows' => 8
]
])
;

]);

return $this;
}
Expand Down
19 changes: 12 additions & 7 deletions src/Goteo/Library/Forms/Model/ProjectRewardsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Symfony\Component\Validator\Constraints;
use Goteo\Library\Text;
use Goteo\Application\Currency;
use Goteo\Application\Session;
use Goteo\Model\Project\Reward;
use Goteo\Library\Forms\FormModelException;
use Goteo\Model\Project;
Expand Down Expand Up @@ -129,13 +130,6 @@ public function addReward(Reward $reward) {
'required' => false,
'color' => 'cyan'
])
->add("subscribable$suffix", BooleanType::class, [
'label' => false,
'data' => $reward->subscribable,
'disabled' => $subs_readonly,
'required' => false,
'color' => 'cyan'
])
->add("reward$suffix", TextType::class, [
'label' => 'regular-title',
'data' => $reward->reward,
Expand All @@ -157,6 +151,7 @@ public function addReward(Reward $reward) {
]

]);

if(!$remove_readonly) {
$this->getBuilder()
->add("remove$suffix", SubmitType::class, [
Expand All @@ -169,6 +164,16 @@ public function addReward(Reward $reward) {
]
]);
}

if (Session::isAdmin()) {
$this->getBuilder()->add("subscribable$suffix", BooleanType::class, [
'label' => false,
'data' => $reward->subscribable,
'disabled' => $subs_readonly,
'required' => false,
'color' => 'cyan'
]);
}
}

public function createForm() {
Expand Down
5 changes: 0 additions & 5 deletions src/Goteo/Payment/Method/StripeSubscriptionPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ public function refund(): ResponseInterface
throw new PaymentException("Refund not yet supported for subscriptions", 1);
}

public function calculateCommission($total_invests, $total_amount, $returned_invests = 0, $returned_amount = 0)
{
// Confirm Stripe commission
}

public function isInternal(): bool
{
return false;
Expand Down
32 changes: 24 additions & 8 deletions src/Omnipay/Stripe/Subscription/Message/SubscriptionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public function getData()
return $this->data;
}

/**
* @param array{user: User, invest: Invest} $data
*/
public function sendData($data)
{
$price = $this->stripe->prices->create([
Expand All @@ -36,17 +39,30 @@ public function sendData($data)
'product' => $this->getStripeProduct($data['invest'])->id
]);

$subscription = $this->stripe->subscriptions->create([
$session = $this->stripe->checkout->sessions->create([
'customer' => $this->getStripeCustomer($data['user'])->id,
'items' => [
['price' => $price->id]
],
'payment_behavior' => 'default_incomplete',
'payment_settings' => ['save_default_payment_method' => 'on_subscription'],
'expand' => ['latest_invoice.payment_intent']
'success_url' => $this->getRedirectUrl('/dashboard/subscriptions'),
'cancel_url' => $this->getRedirectUrl('/project/', $data['invest']->getProject()->id),
'mode' => 'subscription',
'line_items' => [
[
'price' => $price->id,
'quantity' => 1
]
]
]);

return new SubscriptionResponse($this, $subscription);
return new SubscriptionResponse($this, $session);
}

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

private function getStripeCustomer(User $user): Customer
Expand Down
16 changes: 13 additions & 3 deletions src/Omnipay/Stripe/Subscription/Message/SubscriptionResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
namespace Omnipay\Stripe\Subscription\Message;

use Omnipay\Common\Message\AbstractResponse;
use Stripe\Subscription;
use Omnipay\Common\Message\RedirectResponseInterface;

class SubscriptionResponse extends AbstractResponse
class SubscriptionResponse extends AbstractResponse implements RedirectResponseInterface
{
public function isSuccessful()
{
return $this->data instanceof Subscription;
return false;
}

public function isRedirect()
{
return true;
}

public function getRedirectUrl()
{
return $this->data->url;
}
}
2 changes: 2 additions & 0 deletions translations/ca/roles.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
role-name-user: 'Usuari sense privilegis'
role-name-creator: 'Creador de continguts'
role-name-vip: 'Usuari VIP (padrí)'
role-name-translator: 'Traductor de continguts'
role-name-checker: 'Revisor de projectes'
Expand Down Expand Up @@ -54,3 +55,4 @@ role-perm-name-create-matcher: 'Pot crear matchers'
role-perm-name-edit-matcher: 'Pot editar matchers'
role-perm-name-remove-matcher: 'Pot esborrar els seus matchers'
role-perm-name-edit-any-matcher: 'Pot editar qualsevol matcher'
role-perm-name-highlight-project: 'Pot incloure projectes propis al seu perfil de creador'
2 changes: 2 additions & 0 deletions translations/en/roles.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
role-name-user: 'Non privileged user'
role-name-creator: 'Content creator'
role-name-vip: 'VIP user (godfather)'
role-name-translator: 'Content translator'
role-name-checker: 'Project reviewer'
Expand Down Expand Up @@ -55,6 +56,7 @@ role-perm-name-admin-module-workshops: 'Can access the workshop module'
role-perm-name-admin-module-promote: 'Can access the module to promote projects to the home page'
role-perm-name-admin-module-channels: "Can access the channel's administration modules"
role-perm-name-receive-test-communications: 'Can receive test communications'
role-perm-name-highlight-project: 'Can feature own projects in their creator profile'
role-perm-name-create-matcher: 'Create own matcher'
role-perm-name-edit-matcher: 'Edit own matcher'
role-perm-name-remove-matcher: 'Remove own matcher'
Expand Down
5 changes: 4 additions & 1 deletion translations/es/roles.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
role-name-user: 'Usuario sin privilegios'
role-name-creator: 'Creador de contenidos'
role-name-vip: 'Usuario VIP (padrino)'
role-name-translator: 'Traductor de contenidos'
role-name-checker: 'Revisor de proyectos'
Expand Down Expand Up @@ -64,4 +65,6 @@ role-perm-name-create-matcher: 'Puede crear matchers'
role-perm-name-edit-matcher: 'Puede editar matchers'
role-perm-name-remove-matcher: 'Puede borrar sus matchers'
role-perm-name-edit-any-matcher: 'Puede editar cualquier matcher'
role-perm-name-remove-any-matcher: 'Puede borrar cualquier matcher'
role-perm-name-remove-any-matcher: 'Puede borrar cualquier matcher'

role-perm-name-highlight-project: 'Puede destacar proyectos propios en su perfil de creador'

0 comments on commit fa3b68f

Please sign in to comment.