PayPal Subscription API integration. When do I need to create a Product? - paypal

I have to manage the recurring payment for our online service, but there is an aspect not very clear to me.
From what I understand, to manage a subscription I need to:
Create the product
Create the subscription plan
Create the subscription
I have done some tests and everything works correctly.
What I don't understand is whether the product and the respective subscription plan need to be created for each transaction or if I first need to create a product list with their associated subscription plans and always use the same items when creating the subscription.

You need to create the product and subscription plan for the first time. If any person has subscribed to your product, the money will be automatically deducted at the onset of the next billing cycle. It will use the same product and plan for which the person has subscribed for.
For more detail, you can go through https://medium.com/analytics-vidhya/paypal-subscription-in-react-1121c39b26be.

Create new Products and Plans when you have new Products, or are offering new or additional Plans.
Otherwise, use existing items for new Subscriptions.

Related

How to prevent users with Paypal subscription having trial to cancel and have another trial period

I have a SaaS with Paypal subscription.
In Paypal we can have a trial period as a part of the plan, which is managed by Paypal.
Is there any pattern to organize account deletion and subscription cancelation? I see some options?
Users can cancel subscription, but if they want to make a new subscription - they will get a new trial since it's a new subscription. I could get another plan without trial for this, but can't they substitute plan ID with the one with trial with some HTML knowledge?
Subscription cancelation can only be done together with account deletion. User can suspend subscription if he doesn't want to delete the account. Suspension is not exactly like cancelation, looks incomplete, like you may pay accidentally at some point.
Yes, a plan_id on the client side can be changed. You could conceivably create the subscription using the create subscription API call and fetch the ID of the created subscription instead, with a pattern similar to https://developer.paypal.com/demo/checkout/#/pattern/server
Subscriptions can always be cancelled in the payer's PayPal account.
Whatever solution you decide on, register for the webhook PAYMENT.SALE.COMPLETED and build you logic using that. For reconciliation, add a custom_id when the subscription is created; this can essentially be your own user ID or whatever other unique identifier you want.

Apply discounts on subscriptions with PayPal

I am using the PayPal API for subscription, so far on Sandbox and everything works as expected. I have read the whole documentation of PayPal api and unfortunately couldn't find what I need, that's why I'm asking here.
I am recently considering to add Discounts as well, and wish to have that in two ways:
New customer enters the discount code the first time they want to join the company. (e.g. use the Valentines Discount Code and get 10€ on your first month).
Already existing customers get a discount on one of the months. (Let's say they pay 25€ monthly, and they get a 10€ discount in the 3rd month for whatever reason, now the payments look something like this. 25€ 25€ 15€ 25€ etc...).
Is there really no way to add discounts to subscriptions in PayPal? I would be really glad for any hints / help. Thank you.
For discounts at checkout time, when creating the subscription and specifying a plan_id, you can also specify a plan object with different billing cycle values that override it, for example a lower regular amount or an additional lower amount trial period. See the Create Subscription API call; available parameters for the createSubscription JS SDK function are the same.
For discounts after a subscription is active, you will need to update the subscription. This can be done with the Update Subscription patch API call.

Subscription using Express.js and mongodb

Hey I am new to express.js and these days I am working on a project. its like a shop owner created a shop with different plans, each plan has different price, what I want is that, when user pay for that plan then only he will get subscription, how can i do this using express.js, MongoDB and a payment gateway, can anyone help please.
I would suggest having 2 collections for this.
The first one is a users collection where you will save the user information (id, username, encrypted password, etc.).
The second collection will be a payments collection which will have the plan, the id of the user that paid for it and the time it was paid.
Then in order to check the active subscriptions, all you need to do is query all the payments the user paid in the last month (if the subscriptions are monthly) and check what plans they paid for.
This way you will be able to check when they need to pay again (a month after the paid time) and what plan they paid for.
I suggest reading how Stripe subscriptions work and then working through the end to end guide to creating subscriptions, making sure you select the "Node" code snippet tab. The underlying database is up to you, anything will work.

Braintree API Update Subscription

The Braintree API docs aren't entirely clear on a few things dealing with subscriptions.
We're building a system with multiple subscription tiers and want to give the user the ability to change tiers at any time. Updating the subscription is easy enough, and we've enabled prorated billing (though we're still not entirely clear on what Braintree is doing under the hood there).
The part I'm not seeing is how to update the price. If I change the plan id, the price does not change. I would expect the subscription to use the new plan's price - I can't imagine when it would ever make sense to not update the price. I see that I can pass a new price along with a new plan id, so I can update the price in the same call that I update the plan, but this means I have to store the price in my code as well as in Braintree. I know I can call the plans on Braintree to get the price information, but it should not be necessary to add the overhead of an additional API call.
Am I overlooking something? Is there really not a way to tell Braintree to use the price of the new subscription?
I am a developer at Braintree. Our plans are templates that are used to populate the subscription when it is created.
From our docs:
A plan is a template for your subscriptions: when you create a plan, it will be used to populate the following attributes when a new subscription is created:
plan name
description
trial period
billing day of month
number of billing cycles
amount
currency
billing cycle
Additionally our subscriptions do not inherit a new plan's price when updated
If you update the subscription's plan, the subscription will not inherit the new plan's price.
We implemented plans as templates so that merchants can safely update a plan without affecting subscriptions with existing customers.
We try to not make any assumptions about the state of a subscription when the plan id has changed to prevent its values from being changed unexpectedly. There is not a solution at this time to inherit select properties from a plan when changing a plan's subscription.
Since there is no language tag to this question, I'll use PHP.
If your customer changes subscription, what you have to do is update his current subscription in Braintree to the new plan AND set the new price of the plan too in that call.
Basically plans in Braintree are just templates (as said by pblesi). You can override any value you want. You can in theory create a $1/month plan called tiny in Braintree, but in your code subscribe the user to the tiny plan with a $500/month subscription price.
I think (guessing from here on) that Braintree just provides this system so people can add plans to their apps/websites without updating any code, because you can query all existing Braintree plans on your account and populate your GUI with their contents. If you implement something like this you can add plans later on and they will automatically appear on your site/app. On the other hand you can edit the price for existing plans on their site and it would only impact new subscribers as old customers will keep on paying the old price.
Now for the code, in PHP:
First I create a subscription:
Braintree_Subscription::create([
'paymentMethodToken' => $paymentMethodToken,
'planId' => $planId,
'price' => $price
]);
Price is just a number, the currency depends on your account configuration
Imagine my user changes his subscription on the website, I can update his subscription as follows:
Braintree_Subscription::update($subscriptionId,[
'planId' => $planId,
'price' => $price
]);
where $subscriptionId is the ID of the subscription you created when he/she first signed up (to be stored somewhere with the user info in your db for instance), $planId is the new plan and $price is the price of the new plan.
I've just implemented support for Braintree myself, and indeed, the user manual isn't always very clear, but once you know how it works it's actually a very easy system to use. A lot easier than PayPal recurring billing, for that matter.

Paypal subscription to different number of projects

I am trying to create a subscription feature on my site. The users can subscribe to a number of projects (from 1 to 30). The price of a projet: 10$.
For subscribing I use a the Subscription button. I validate the payment using the IPN from paypal. All ok.
Now I want to give to users the possibility to change the number of projects they are subscribed for. But the paypal doesn't allow an increasing of payment more than 20%.
How can I change the user's subscription ? Should I remove his profile (not sure if I understant what it is) and create a new one ?
As you saw in the documentation, PayPal Subscriptions product doesn't seem like a good match for your requirements. You could have someone re-subscribe with new (higher) premium, but you probably would be better off with a product that allowed you to simply change the recurring amount billed.
PayPal has several other products that allow you to do that; hopefully one will meet your needs. In particular look at Recurring Payments & Reference Transactions (within PayPal's classic product suite) or Future Payments (within PayPal's RESTful API suite).