Recurring Payment

Simon Hürlimann edited this page Sep 26, 2013 · 8 revisions

Recurring Payment

Setup transaction

Call SetExpressCheckout using this code and let user redirect to the given redirect URI.

request =
  :username   => SET_YOUR_OWN,
  :password   => SET_YOUR_OWN,
  :signature  => SET_YOUR_OWN
payment_request =
  :currency_code => :JPY, # if nil, PayPal use USD as default
  :billing_type  => :RecurringPayments,
  :billing_agreement_description => SET_YOUR_OWN
response = request.setup(

Assume the end-user approved the payment request on and redirect back to your site.
In the redirect back request, you get token in query string.

Create Recurring Profile

Call CreateRecurringPaymentsProfile using this code. Ensure the description matches the description in the PaymentRequest.

profile =
  :start_date => SET_YOUR_OWN,
  :description => SET_YOUR_OWN,
  :billing => {
    :period        => SET_YOUR_OWN, # ie.) :Month, :Week
    :frequency     => SET_YOUR_OWN,
    :amount        => SET_YOUR_OWN,
    :currency_code => :JPY # if nil, PayPal use USD as default
response = request.subscribe!(token, profile)
# inspect this attribute for more details
response.recurring.identifier # => profile_id

Get subscription details

You can get recurring profile details anytime.
Call GetRecurringPaymentsProfileDetails using this code.

response = request.subscription(profile_id)
# inspect this attribute for more details

Cancel (unsubscribe) / Suspend / Reactivate profile

Call ManageRecurringPaymentsProfileStatus using this code.

request.renew!(profile_id, :Cancel)
request.renew!(profile_id, :Suspend)
request.renew!(profile_id, :Reactivate)