Class: PayPal::Recurring::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/paypal/recurring/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



35
36
37
# File 'lib/paypal/recurring/base.rb', line 35

def initialize(options = {})
  options.each {|name, value| send("#{name}=", value)}
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



4
5
6
# File 'lib/paypal/recurring/base.rb', line 4

def amount
  @amount
end

#cancel_urlObject

Returns the value of attribute cancel_url.



5
6
7
# File 'lib/paypal/recurring/base.rb', line 5

def cancel_url
  @cancel_url
end

#currencyObject

Returns the value of attribute currency.



6
7
8
# File 'lib/paypal/recurring/base.rb', line 6

def currency
  @currency
end

#descriptionObject

Returns the value of attribute description.



7
8
9
# File 'lib/paypal/recurring/base.rb', line 7

def description
  @description
end

#emailObject

Returns the value of attribute email.



9
10
11
# File 'lib/paypal/recurring/base.rb', line 9

def email
  @email
end

#failedObject

Returns the value of attribute failed.



10
11
12
# File 'lib/paypal/recurring/base.rb', line 10

def failed
  @failed
end

#frequencyObject

Returns the value of attribute frequency.



11
12
13
# File 'lib/paypal/recurring/base.rb', line 11

def frequency
  @frequency
end

#initial_amountObject

Returns the value of attribute initial_amount.



12
13
14
# File 'lib/paypal/recurring/base.rb', line 12

def initial_amount
  @initial_amount
end

#initial_amount_actionObject

Returns the value of attribute initial_amount_action.



13
14
15
# File 'lib/paypal/recurring/base.rb', line 13

def initial_amount_action
  @initial_amount_action
end

#ipn_urlObject

Returns the value of attribute ipn_url.



14
15
16
# File 'lib/paypal/recurring/base.rb', line 14

def ipn_url
  @ipn_url
end

#item_amountObject

Returns the value of attribute item_amount.



28
29
30
# File 'lib/paypal/recurring/base.rb', line 28

def item_amount
  @item_amount
end

#item_categoryObject

Returns the value of attribute item_category.



26
27
28
# File 'lib/paypal/recurring/base.rb', line 26

def item_category
  @item_category
end

#item_nameObject

Returns the value of attribute item_name.



27
28
29
# File 'lib/paypal/recurring/base.rb', line 27

def item_name
  @item_name
end

#item_quantityObject

Returns the value of attribute item_quantity.



29
30
31
# File 'lib/paypal/recurring/base.rb', line 29

def item_quantity
  @item_quantity
end

#localeObject

Returns the value of attribute locale.



15
16
17
# File 'lib/paypal/recurring/base.rb', line 15

def locale
  @locale
end

#noteObject

Returns the value of attribute note.



8
9
10
# File 'lib/paypal/recurring/base.rb', line 8

def note
  @note
end

#outstandingObject

Returns the value of attribute outstanding.



16
17
18
# File 'lib/paypal/recurring/base.rb', line 16

def outstanding
  @outstanding
end

#payer_idObject

Returns the value of attribute payer_id.



17
18
19
# File 'lib/paypal/recurring/base.rb', line 17

def payer_id
  @payer_id
end

#periodObject

Returns the value of attribute period.



18
19
20
# File 'lib/paypal/recurring/base.rb', line 18

def period
  @period
end

#profile_idObject

Returns the value of attribute profile_id.



19
20
21
# File 'lib/paypal/recurring/base.rb', line 19

def profile_id
  @profile_id
end

#referenceObject

Returns the value of attribute reference.



20
21
22
# File 'lib/paypal/recurring/base.rb', line 20

def reference
  @reference
end

#refund_typeObject

Returns the value of attribute refund_type.



21
22
23
# File 'lib/paypal/recurring/base.rb', line 21

def refund_type
  @refund_type
end

#return_urlObject

Returns the value of attribute return_url.



22
23
24
# File 'lib/paypal/recurring/base.rb', line 22

def return_url
  @return_url
end

#start_atObject

Returns the value of attribute start_at.



23
24
25
# File 'lib/paypal/recurring/base.rb', line 23

def start_at
  @start_at
end

#tokenObject

Returns the value of attribute token.



24
25
26
# File 'lib/paypal/recurring/base.rb', line 24

def token
  @token
end

#transaction_idObject

Returns the value of attribute transaction_id.



25
26
27
# File 'lib/paypal/recurring/base.rb', line 25

def transaction_id
  @transaction_id
end

#trial_amountObject

Returns the value of attribute trial_amount.



33
34
35
# File 'lib/paypal/recurring/base.rb', line 33

def trial_amount
  @trial_amount
end

#trial_frequencyObject

Returns the value of attribute trial_frequency.



30
31
32
# File 'lib/paypal/recurring/base.rb', line 30

def trial_frequency
  @trial_frequency
end

#trial_lengthObject

Returns the value of attribute trial_length.



31
32
33
# File 'lib/paypal/recurring/base.rb', line 31

def trial_length
  @trial_length
end

#trial_periodObject

Returns the value of attribute trial_period.



32
33
34
# File 'lib/paypal/recurring/base.rb', line 32

def trial_period
  @trial_period
end

Instance Method Details

#cancelObject

Cancel a recurring profile. Cancelled profiles cannot be reactivated.

ppr = PayPal::Recurring.new(:profile_id => "I-HYRKXBMNLFSK")
response = ppr.cancel


106
107
108
# File 'lib/paypal/recurring/base.rb', line 106

def cancel
  request.run(:manage_profile, :action => :cancel, :profile_id => profile_id)
end

#checkoutObject

Request a checkout token.

ppr = PayPal::Recurring.new({
  :return_url         => "http://example.com/checkout/thank_you",
  :cancel_url         => "http://example.com/checkout/canceled",
  :ipn_url            => "http://example.com/paypal/ipn",
  :description        => "Awesome - Monthly Subscription",
  :amount             => "9.00",
  :currency           => "USD"
})

response = ppr.request_token
response.checkout_url


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/paypal/recurring/base.rb', line 59

def checkout
  params = collect(
    :locale,
    :amount,
    :return_url,
    :cancel_url,
    :currency,
    :description,
    :ipn_url,
    :item_category,
    :item_name,
    :item_amount,
    :item_quantity
  ).merge(
    :payment_action => "Authorization",
    :no_shipping => 1,
    :L_BILLINGTYPE0 => "RecurringPayments"
  )

  request.run(:checkout, params)
end

#checkout_detailsObject

Return checkout details.

ppr = PayPal::Recurring.new(:token => "EC-6LX60229XS426623E")
response = ppr.checkout_details


115
116
117
# File 'lib/paypal/recurring/base.rb', line 115

def checkout_details
  request.run(:details, :token => token)
end

#create_recurring_profileObject

Create a recurring billing profile.

ppr = PayPal::Recurring.new({
  :amount                => "9.00",
  :initial_amount        => "9.00",
  :initial_amount_action => :cancel,
  :currency              => "USD",
  :description           => "Awesome - Monthly Subscription",
  :ipn_url               => "http://example.com/paypal/ipn",
  :frequency             => 1,
  :token                 => "EC-05C46042TU8306821",
  :period                => :monthly,
  :reference             => "1234",
  :payer_id              => "WTTS5KC2T46YU",
  :start_at              => Time.now,
  :failed                => 1,
  :outstanding           => :next_billing,
  :trial_period          => :monthly,
  :trial_length          => 1,
  :trial_frequency       => 1,
  :trial_amount          => 0.00
})

response = ppr.create_recurring_profile


175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/paypal/recurring/base.rb', line 175

def create_recurring_profile
  params = collect(
    :amount,
    :initial_amount,
    :initial_amount_action,
    :currency,
    :description,
    :payer_id,
    :token,
    :reference,
    :start_at,
    :failed,
    :outstanding,
    :ipn_url,
    :frequency,
    :period,
    :email,
    :trial_length,
    :trial_period,
    :trial_frequency,
    :trial_amount,
    :item_category,
    :item_name,
    :item_amount,
    :item_quantity
  )
  request.run(:create_profile, params)
end

#profileObject

Retrieve information about existing recurring profile.

ppr = PayPal::Recurring.new(:profile_id => "I-VCEL6TRG35CU")
response = ppr.profile


242
243
244
# File 'lib/paypal/recurring/base.rb', line 242

def profile
  request.run(:profile, :profile_id => profile_id)
end

#reactivateObject

Reactivate a suspended recurring profile.

ppr = PayPal::Recurring.new(:profile_id => "I-HYRKXBMNLFSK")
response = ppr.reactivate


96
97
98
# File 'lib/paypal/recurring/base.rb', line 96

def reactivate
  request.run(:manage_profile, :action => :reactivate, :profile_id => profile_id)
end

#refundObject

Request a refund.

ppr = PayPal::Recurring.new({
  :profile_id => "I-VCEL6TRG35CU",
  :transaction_id => "ABCEDFGH",
  :reference      => "1234",
  :refund_type    => :partial,
  :amount         => "9.00",
  :currency       => "USD"
})
response = ppr.refund


257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/paypal/recurring/base.rb', line 257

def refund
  params = collect(
    :transaction_id,
    :reference,
    :refund_type,
    :amount,
    :currency,
    :note
  )

  request.run(:refund, params)
end

#requestObject

Just a shortcut convenience.



41
42
43
# File 'lib/paypal/recurring/base.rb', line 41

def request # :nodoc:
  @request ||= Request.new
end

#request_paymentObject

Request payment.

# ppr = PayPal::Recurring.new({
  :token       => "EC-6LX60229XS426623E",
  :payer_id    => "WTTS5KC2T46YU",
  :amount      => "9.00",
  :description => "Awesome - Monthly Subscription"
})
response = ppr.request_payment
response.completed? && response.approved?


130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/paypal/recurring/base.rb', line 130

def request_payment
  params = collect(
    :amount,
    :return_url,
    :cancel_url,
    :ipn_url,
    :currency,
    :description,
    :payer_id,
    :token,
    :reference,
    :item_category,
    :item_name,
    :item_amount,
    :item_quantity
  ).merge(:payment_action => "Sale")

  request.run(:payment, params)
end

#suspendObject

Suspend a recurring profile. Suspended profiles can be reactivated.

ppr = PayPal::Recurring.new(:profile_id => "I-HYRKXBMNLFSK")
response = ppr.suspend


87
88
89
# File 'lib/paypal/recurring/base.rb', line 87

def suspend
  request.run(:manage_profile, :action => :suspend, :profile_id => profile_id)
end

#update_recurring_profileObject

Update a recurring billing profile.

ppr = PayPal::Recurring.new({
  :amount                => "99.00",
  :currency              => "USD",
  :description           => "Awesome - Monthly Subscription",
  :note                  => "Changed plan to Gold",
  :ipn_url               => "http://example.com/paypal/ipn",
  :reference             => "1234",
  :profile_id            => "I-VCEL6TRG35CU",
  :start_at              => Time.now,
  :outstanding           => :next_billing
})

response = ppr.update_recurring_profile


220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/paypal/recurring/base.rb', line 220

def update_recurring_profile
  params = collect(
    :amount,
    :currency,
    :description,
    :note,
    :profile_id,
    :reference,
    :start_at,
    :outstanding,
    :ipn_url,
    :email
  )

  request.run(:update_profile, params)
end