Recurring Payment - nov/paypal-express GitHub Wiki
Call SetExpressCheckout using this code and let user redirect to the given redirect URI.
request = Paypal::Express::Request.new(
:username => SET_YOUR_OWN,
:password => SET_YOUR_OWN,
:signature => SET_YOUR_OWN
)
payment_request = Paypal::Payment::Request.new(
:currency_code => :JPY, # if nil, PayPal use USD as default
:billing_type => :RecurringPayments,
:billing_agreement_description => SET_YOUR_OWN
)
response = request.setup(
payment_request,
YOUR_SUCCESS_CALBACK_URL,
YOUR_CANCEL_CALBACK_URL
)
response.redirect_uriAssume the end-user approved the payment request on PayPal.com and redirect back to your site.
In the redirect back request, you get token in query string.
Call CreateRecurringPaymentsProfile using this code. Ensure the description matches the description in the PaymentRequest.
profile = Paypal::Payment::Recurring.new(
: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
response.recurring.identifier # => profile_idYou can get recurring profile details anytime.
Call GetRecurringPaymentsProfileDetails using this code.
response = request.subscription(profile_id)
# inspect this attribute for more details
response.recurringCall ManageRecurringPaymentsProfileStatus using this code.
request.renew!(profile_id, :Cancel)
request.renew!(profile_id, :Suspend)
request.renew!(profile_id, :Reactivate)