Stripe Checkout with django-stripe: how pass fees on to customers (surcharging)? - django

I am using django-stripe to generate Stripe Checkouts.
I would like to pass the Stripe fees on to my customers ("surcharging").
I found a help article from stripe regarding this. It says in general how to calculate the fees to put on top of the price of the product.
The problem is, that different payment methods have different fees.
And when creating the Checkout, I must calculate the final price (including the fees I want to pass on) before I know what payment method the customer will select (and therefore what fees the customer will have to pay).
So I don't know the fees when I must put them on top of the price the user has to pay in the Checkout.
Is there a way out of this dilemma?

Unfortunately there isn't a way to dynamically change the price based on the payment method presently. You must specify the amount to be paid prior to redirecting your customers to the Stripe Checkout interface.
You could create make your users select a Payment Method prior to redirecting them to Checkout (restricting the payment_method_types to their selection) and adjust the price based on their chosen Payment Method. But that requires a lot of work on your side and loses some of the nicest features of Stripe Checkout.

Related

Stripe Webhooks: Invoice.paid vs Checkout.Session.Completed

I use Stripes' webhooks and want to get notified, if the customer successfully "paid the bill". I came across two webhooks, which in my opinion both could do the job:
Webhook "invoice.paid" - According to Stripe doc: Occurs whenever an invoice payment attempt succeeds or an invoice is marked as paid out-of-band.
Webhook "checkout.session.completed" - According to Stripe doc: Occurs when a Checkout Session has been successfully completed.
My questions are:
I don't understand the second part of the "invoice.paid" webhook: "invoice is marked as paid out-of-band" -> What does "out-of-band" mean? Is this to be considered a successful payment?
Regarding "checkout.session.complete" -> This can also occur, if payment fails - correct?
Which webhooks shall I consider (or are there other webhooks) to see the status "customer paid the bill successfully"?
What is more, I don't really know if disputes should be considered as successful payments or not: On one hand, I get a invoice.paid webhook, on the other hand, I get a charge.dispute.created webhook. geeezus...
I appreciate your help! Thanks.
I don't understand the second part of the "invoice.paid" webhook: "invoice is marked as paid out-of-band" -> What does "out-of-band" mean? Is this to be considered a successful payment?
This is specifically referring to marking an invoice paid out of band (ie, the customer paid you outside of Stripe and you want to mark the Stripe invoice paid without collecting a payment). This will not involve an actual payment, but does transition the invoice to status=paid so this event fires.
Regarding "checkout.session.complete" -> This can also occur, if payment fails - correct?
This event signals only that the Checkout session is complete. Depending on the mode use for Checkout, this may or may not involve a payment. If an immediate payment is expected, the session will only complete if that payment is successful. For example mode=setup or mode=subscription with a free trial will not involve an immediate payment. A subscription with trial, though, will create a $0 invoice and fire invoice.paid.
Which webhooks shall I consider (or are there other webhooks) to see
the status "customer paid the bill successfully"?
This depends on what you mean by "paid" and "bill". If you mean specifically for invoices (whether related to subscriptions or not), then invoice.paid is a good choice. You can then filter for amounts greater than $0 etc to further constrain was "paid" means.
What is more, I don't really know if disputes should be considered as
successful payments or not: On one hand, I get a invoice.paid webhook,
on the other hand, I get a charge.dispute.created webhook.
Disputes are not payments, and should be an entirely separate discussion. You can only have a dispute after a payment. Suggest starting by reading the docs on disputes.
To summarize: What are you really trying to do? These events are related and sometimes overlap, but not always. It highly depends on what you're doing.
What's going on?
When you create a checkout session it will have an id, which you'll store in your database next to the user who started the checkout session.
When you receive an invoice.paid webhook event, it does not have any link back to the checkout session! (so you'll know someone paid, but you won't know who paid!)
checkout.session.completed solves this because it contains the id of the checkout session and the stripe customer id, which allows you to link the two, so you basically have a mapping from your customer ids to stripe's customer ids.
So simply grab the customer id from the checkout.session.completed event and store it in your database next to the relevant user, that way you'll be able to tell which one of your users is paying you when you receive an invoice.paid event!
How can this be implemented?
When a checkout session is started, store the checkout session id next to the user who started the session so you can look it up later
When you see checkout.session.completed, look at the accompanying JSON and take the stripe customer number and store it in your database (e.g. a column like stripe_id in users table). To figure out which of your users it's for, use the checkout session id to look it up in your database (i.e. the data you stored in step 1)
Now that you have the stripe customer id stored in your users table, whenever you see invoice.paid, look at the accompanying JSON, take the stripe customer number, look it up in your users table to find who paid, and update the expiry date of their subscription to 1 month into the future.
That's it!
Also good to know
Both checkout.session.completed and invoice.paid events are triggered when someone new subscribes, and only invoice.paid is triggered each month thereafter (presuming the user had enough funds and didn't cancel)
You can get to the stripe customer number in both webhook events like so (this is ruby, but should be similar with js or python):
payload = request.body.read
data = JSON.parse(payload, symbolize_names: true)
data.object.customer
=> "cus_Lvyv721cJGpYB1"

In OpenCart, how to make customers get a discount if choose a specific payment method?

In OpenCart, how do you make customers receive a discount if they chose "western union" payment?
The desired effect is that the total would auto-change, once the customer clicks to select "western union" payment.
You would need to create an order total module that implemented this discount. You'd check the payment type, and trigger if it was Western Union.

Change cart amount in prestashop

I want to add our custom amount in total cart amount during checkout or payment in prestashop in custom payment module. And so can i change cart amount during checkout or payment in our custom payment module in prestashop?
There are three options I spontaneously know about:
Use an already available module for such purpose. In this case, there is in example the Additional Payment Fees module (which I use in production in a PrestaShop installation myself).
Write an additional module which can apply configurable fees on selectable payment options. This might be the favored option and bases on the same principles as the next.
Make your payment module use a specific cart rule.
I checked it again and cart rules do not appear to be a good idea for adding fees rather than discounts. In fact, the PrestaShop Back-Office does not allow to set up cart rules with negative "discounts".
These are the things to take care about:
Its best to add the fee distinct from the actually purchased products and eventual shipping costs to maintain transparency towards the customer. This might not be a technical detail, but valuable concerning user experience.
Display the additional fees for a payment type on the cart page. The hookdisplayShoppingCart or displayShoppingCartFooter is suitable for that. These hooks can also be used to initiate calculation of payment fees and storing them in association with the cart because calculation is necessary only when the customer is confronted with the choice of payment: in the cart.
Create an additional column in the cart table or alternatively a dedicated table which holds the fee information for each cart. This information must be stored permanently as it is necessary even after finished order.
Getting the cart's total value is easy: $this->context->cart->getOrderTotal(); - but keep in mind that this includes tax (provide false as first parameter). I am not sure about whether such fee must be applied to the net or gross value of the cart.
They must be visible on the invoice, too. In that case the displayPDFInvoice hook is suitable for inserting additional information into the invoice PDF.
I am sorry I did not find yet how to finally apply the fee to the cart for checkout but I hope it helps if I point into the direction of tax rules, which you could leverage programmatically for each order.
Sources
PrestaShop 1.5 documentation about hooks
PrestaShop 1.5 documentation about tax rules
PrestaShop 1.5.6.2 Cart class

How to get shipping costs of an order with Amazon MWS Api?

I would like to get shipping costs of an order. I can get amount, customer information, purchase date of an order... but where is the shipping cost?
Any code or link would be very helpful.
Thanks.
Assuming that you are using the Orders API, the shipping charges for each item are stored in the shippingPrice property of the OrderItem type. You need to use the ListOrderItems operation to retrieve the order's items.
See page 26 of the Orders API documentation for a description of shippingPrice property. See page 25 for a description of the ListOrderItems operation.

django models - best practice for annual subscription management

I'm looking for advice on best practice for annual subscription management where the fees may change each year.
I have a Membership and MemshipYear models as well as the User models. Each membership category (membership.category) has an annual fee which may be different. Members will be able to download pdf invoices for membership fees at any time once logged in.
The pdf is generated at the time of request and the data is taken from the membership model. Therefore if the membership fee changes after one year the invoice would be caluclated with this figure and not the fee for that year.
One thought I had was to use price banding i.e A-F, and have a price band for each category for each year.
I reckon there's a better way.Anyone?
Logically, the membership itself should have a price, since that inherently belongs to the user. On creation, you would set this value from the category. Then, whenever you need to get the current price the user is paying, you pull it from their membership, instead of the variable price on the category.