Harry
Harry

Reputation: 13329

Paypal subscription process flow

Im using paypal with Django. This is the scenario. The user is logged in, he has not payed for the service. Once payed, I must update his user profile as "payed = True". Then he will have access to the full site.

Im struggeling to understand how this must be intergrated with paypal. I get the payments working successfully. But then how does my server know what user it will be fore when paypal bills the user?

Im thinking there must be a field for me to send to paypal, like a user id, and then paypal must send that to me when its doing a payment, so I can see which user it is?

How do you implement this with paypal?

Create the button

paypal_dict = {
    "cmd": "_xclick-subscriptions",
    "business": settings.PAYPAL_RECEIVER_EMAIL,
    "a3": "5.00",                      # monthly price
    "p3": 1,                           # duration of each unit (depends on unit)
    "t3": "M",                         # duration unit ("M for Month")
    "src": "1",                        # make payments recur
    "sra": "1",                        # reattempt payment on payment error
    "no_note": "1",                    # remove extra notes (optional)
    "item_name": "Test monthly subscription",
    "notify_url": "http://localhost:8000/payment/",
    "return_url": "http://localhost:8000/",
    "cancel_return": "http://localhost:8000/",
    "custom":request.user.get_profile().pk
}

# Create the instance.
ppform = PayPalPaymentsForm(initial=paypal_dict, button_type="subscribe")

Upvotes: 0

Views: 352

Answers (2)

knbk
knbk

Reputation: 53669

You can set an "invoice" to a unique value for each user. Make sure that the value is somehow saved and connected to the user. Each PayPal IPN for that specific subscription will contain the invoice id you sent through the paypal button.

See HTML Variables for Recurring Payments Buttons.

Upvotes: 1

wolendranh
wolendranh

Reputation: 4292

I think payer id should fit to your needs.

payer object

This object includes information about the payer including payment method, funding instruments, and details about the payer.

You can save id, and connect it with your user, then you will know which user should be billed, and use this id to make request to PayPal

Here is link for more info.

Upvotes: 2

Related Questions