forked from nov/paypal-express
-
Notifications
You must be signed in to change notification settings - Fork 0
Recurring Payment
nov matake edited this page May 23, 2011
·
7 revisions
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_uri
Assume 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.
profile = Paypal::Payment::Recurring.new(
:start_date => SET_YOUR_OWN,
:description => 'iKnow! Subscription',
: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_id
You can get recurring profile details anytime.
Call GetRecurringPaymentsProfileDetails
using this code.
response = request.subscription(profile_id)
# inspect this attribute for more details
response.recurring
Call ManageRecurringPaymentsProfileStatus
using this code.
request.renew!(profile_id, :Cancel)
request.renew!(profile_id, :Suspend)
request.renew!(profile_id, :Reactivate)