Skip to content

Commit

Permalink
pass the onBehalfOf parameter to Stripe.js
Browse files Browse the repository at this point in the history
closes #2388
  • Loading branch information
Changaco committed Sep 10, 2024
1 parent 25dbdfd commit bbc1270
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion js/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ Liberapay.stripe_form_init = function($form) {
var stripe = null;
if (window.Stripe) {
stripe = Stripe($form.data('stripe-pk'));
var elements = stripe.elements();
var elements = stripe.elements({
onBehalfOf: $form.data('stripe-on-behalf-of'),
});
var element_type = $container.data('type');
var options = {style: {
base: {
Expand Down
13 changes: 13 additions & 0 deletions www/%username/giving/pay/stripe/%payin_id.spt
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,19 @@ if tippees:
LIMIT 1
""", tippee_ids=tuple(tip.tippee for tip in tips))
)
stripe_on_behalf_of = ''
if len(tips) == 1:
proto_transfers = resolve_tip(
website.db, tips[0], tips[0].tippee_p, 'stripe', payer, payer.guessed_country,
tips[0].periodic_amount
)
if len(proto_transfers) == 1:
if proto_transfers[0].destination.country not in constants.SEPA:
stripe_on_behalf_of = proto_transfers[0].destination.id
del proto_transfers
del tips
# Note: the `stripe_on_behalf_of` value isn't 100% accurate. This can be fixed
# later if it causes too many problems.

elif not payin_id:
response.redirect(payer.path('giving/pay'))
Expand Down Expand Up @@ -377,6 +389,7 @@ title = _("Funding your donations")
"make sure it’s allowing requests to the “stripe.com” domain."
) }}'
data-msg-submitting="{{ _('Request in progress, please wait…') }}"
data-stripe-on-behalf-of="{{ stripe_on_behalf_of }}"
data-stripe-pk="{{ website.app_conf.stripe_publishable_key }}">
<input type="hidden" name="csrf_token" value="{{ csrf_token }}" />
% if len(payment.recipient_names) == 1
Expand Down

0 comments on commit bbc1270

Please sign in to comment.