20

I am using Django paypalrestsdk for PayPal https://github.com/paypal/PayPal-Python-SDK

And I would like to setup a monthly subscription plan. Every beginning of the month, the buyer will be charged USD100.

This is my billing plan code I have made:

billing_plan = paypalrestsdk.BillingPlan({
    "name": "Monthly Billing Plan",
    "description": "Monthly Plan",
    "merchant_preferences": {
        "auto_bill_amount": "yes",
        "cancel_url": "http://localhost:8000/payment_billing_agreement_cancel",
        "initial_fail_amount_action": "continue",
        "max_fail_attempts": "0",
        "return_url": "http://localhost:8000/payment_billing_agreement_execute",
        "setup_fee": {
            "currency": "USD",
            "value": "100"
        }
    },
    "payment_definitions": [
        {
            "amount": {
                "currency": "USD",
                "value": "100"
            },
            "cycles": "0",
            "frequency": "MONTH",
            "frequency_interval": "1",
            "name": "Monthly Payment",
            "type": "REGULAR"
        }
    ],
    "type": "INFINITE"
})

It is not clear to me if it is charging on the first day of the month or the last day of the month? Should I have the setup so it's charged immediately? My intention is charging is done on the first day of the month.

I am seeing this in the sandbox of the buyer: Preapproved payment USD100 What does this mean, is he charged already USD100 or preapproved and charged on the last day of the month?

Based on this, it seems like its charged right away. meaning it should show USD200 right? (setup + monthly but its showing only USD100) https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/subscription_billing_cycles/

I've used this flow so far:

create billing plan
activate billing plan
create billing agreement 
execute billing agreement

(is this correct? it shows pre-approved but is this really charged, if not what other steps should be taken to charge it properly)

To clarify, the main question is how do you set up monthly billing with PayPal (and to set the charging cycle, whether it's beginning of the month or end)? (in this example, its using django python)

UPDATE:

On a recommendation @john-moutafis, I'ved now have setup USD100, and recurring start date is set 1 month later for USD111

    billing_agreement = paypalrestsdk.BillingAgreement({
        "name": "Monthly Billing Agreement",
        "description": "Monthly Payment Agreement",
        "start_date": arrow.utcnow().shift(months=+1).datetime.strftime('%Y-%m-%dT%H:%M:%SZ'),
        "plan": {
            "id": billing_plan.id
        },
        "payer": {
            "payment_method": "paypal"
        }
    })

Here is paypal screenshots, why is there no info on amount and why is it preapproved without recurring info ? https://i.stack.imgur.com/w1HHN.jpg

Axil
  • 3,606
  • 10
  • 62
  • 136

1 Answers1

6

Paypal will automatically try to keep the billing date the same for every month (where applicable, as stated in the linked resource).

You can state the starting date of a billing agreement as stated in this example, by specifying a start_datefield.
Here I use the arrow module, to conveniently calculate the first day of the next month:

import arrow

billing_plan = paypalrestsdk.BillingPlan({
    "name": "Monthly Billing Plan",
    "description": "Monthly Plan",
    "start_date": arrow.utcnow().shift(months=+1).replace(day=1).isoformat(),
    "merchant_preferences": {
        ...
        "setup_fee": {
            "currency": "USD",
            "value": "100"
        }
    }
    ...
})

The initial subscription fee should be handled by the setup_fee field!


EDIT after question update:

On the merchant_preferences field of your plan, you are setting auto_bill_amount to yes.
By taking a look at the documentation on merchant_preferences we can see that:

auto_bill_amount enum

Indicates whether PayPal automatically bills the outstanding balance in the next billing cycle. The outstanding balance is the total amount of any previously failed scheduled payments. Value is:

NO. PayPal does not automatically bill the customer the outstanding >balance.
YES. PayPal automatically bills the customer the outstanding balance.

Possible values: YES, NO.

Default: NO.

Community
  • 1
  • 1
John Moutafis
  • 22,254
  • 11
  • 68
  • 112
  • SO @Axil, how did this roll as a solution? – John Moutafis Apr 26 '18 at 15:11
  • there is some typo errors: "start_date": arrow.utcnow().shift(months=+1).replace(day=1), – Axil Apr 29 '18 at 11:39
  • im getting this error: TypeError: Object of type 'Arrow' is not JSON serializable, need to convert the arrow object into ISO date – Axil Apr 29 '18 at 11:39
  • fix with this "start_date": arrow.utcnow().shift(months=+1).replace(day=1).isoformat(), – Axil Apr 29 '18 at 11:45
  • however, it failed {'name': 'MALFORMED_REQUEST', 'message': 'Incoming JSON request does not map to API request', 'information_link': 'https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST', 'debug_id': '155e9f4dce2ff'} – Axil Apr 29 '18 at 11:46
  • please check update above, i got some success but im not sure if its correct. "setup" i use it for BillingPlan and "start_date" i use it for BillingAgreement – Axil Apr 30 '18 at 00:45
  • Here is paypal screenshots, why is there no info on amount and why is it preapproved without recurring info ? https://imgur.com/a/Sp7JdVC, anyway I emailed to paypal on this as well – Axil Apr 30 '18 at 08:36
  • @Axil I made an edit fixing the `arrow` call and added a suggestion for your second question. – John Moutafis May 04 '18 at 06:49
  • auto_bill_amount enum if it is YES like now, i dont see a charge in the sandbox? I probably want paypal to handle recuuring billing so it should be a YES right? – Axil May 04 '18 at 07:09
  • @Axil Yes, that seems preferred. – John Moutafis May 04 '18 at 07:29
  • the issue now is ok, i'ved done both billingplan and billingagreement, why dont I see it being charged ? it has things like preapproval, etc. can you check the screenshots https://imgur.com/a/Sp7JdVC. is there further steps to charge the paypal account/credit card ? – Axil May 04 '18 at 10:06
  • @Axil I do believe that if you search the PayPal documentation carefully you will find a solution. In case you don't find what you are looking for, you can create a new question here on SO detailing your problem. I am suggesting this to you because asking multiple questions in a single post (or in the comments) is not a good SO practice. – John Moutafis May 04 '18 at 10:10
  • i just made it clearer the title now the objective is making sure i charge first time and making it recurring. i think its important its an all in one, now that i have set a bounty for this. the issue is how to get subscription work. i have also emailed to paypal, over 3 days now waiting. read through the documentation and its not clear to me. So need to seek advise people who have done subscription payment flow with paypal. – Axil May 04 '18 at 10:14