creative-paypal-express 1.0.1.dev2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 917b4f58ef1ec863c24c949d5ff081c56cb96e80
4
- data.tar.gz: b0e5f9a5499dd4e80e4a39cdbc4a0b4dc398e24f
3
+ metadata.gz: 2623304761cdf500c82acefe85e8e626bbd306bb
4
+ data.tar.gz: ba7be3ba0b865c979e3ad4de9272c670b7a6f1b4
5
5
  SHA512:
6
- metadata.gz: 1dfb3339c45ea9cd25fa9ac205d1f66a467d39eecff8831d221c83bbbe3fc60e9e8497ff3bf05ad7b9cccf9d45dba78625351d518fdfe2317ec096150e6857f2
7
- data.tar.gz: 990ea74daa868e7603ec394f7dba71a4a8d48673d18f35ecf504f669fb06f2e14477e1c9055f7e9e94af3994004fcf25f302b65b13f8f0f70ae02bf635f45c86
6
+ metadata.gz: b964a4a4906cb4ccfbd0a794e8a07e5995d2634709eda97692ba073fdbc3ef1f6b94bf4ade0a7d5f300b85d469d26397de4c5aebb4e9c7720f15cb8905f9471d
7
+ data.tar.gz: f0ce0d81a873f140d567ad79743cdeb7d0d115f97d14028ca75212e9b8dd6b5301013b2ab96bdd3e0a930a6482f3e87331ca4bdc1479c1209bc929f7794c966b
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # paypal-express
2
2
 
3
- Handles PayPal Express Checkout.
4
- Both Instance Payment and Recurring Payment are supported.
5
- Express Checkout for Digital Goods is also supported.
3
+ Handle PayPal Express Checkout.
4
+ Both Instance Payment and Recurring Payment are supported.
5
+ Express Checkout for Digital Goods is also supported.
6
6
 
7
7
  ## Installation
8
8
 
@@ -10,11 +10,67 @@ Express Checkout for Digital Goods is also supported.
10
10
  gem "creative-paypal-express", "~> 1.0.0"
11
11
  ```
12
12
 
13
+ gem install paypal-express
14
+
13
15
  ## Usage
14
16
 
15
17
  See Wiki on Github
16
18
  https://github.com/nov/paypal-express/wiki
17
19
 
20
+ Play with Sample Rails App
21
+ https://github.com/nov/paypal-express-sample
22
+ https://paypal-express-sample.heroku.com
23
+
24
+ ## v1.1.0 news (not in wiki)
25
+ ### Paypal::Payment::Recurring
26
+ The helper object can be instantiated by using the :raw key.
27
+
28
+ ```rb
29
+ params = {
30
+ # optional initial payment parameters
31
+ :INITAMT => "9.00",
32
+ :FAILEDINITAMTACTION => "CancelOnFailure", # or "ContinueOnFailure"
33
+
34
+ # optional trial parameters
35
+ :TRIALBILLINGPERIOD => "Day",
36
+ :TRIALBILLINGFREQUENCY => "7",
37
+ :TRIALAMT => "0.00",
38
+ :TRIALCURRENCYCODE => "EUR",
39
+ :TRIALTOTALBILLINGCYCLES => "1",
40
+
41
+ # mandatory regular recurring profile parameters
42
+ :DESC => "Funny Movie Clips Subscription",
43
+ :PROFILESTARTDATE => "2017-01-25T15:00:00Z",
44
+ :BILLINGPERIOD => "Day", # "Month", "Year"
45
+ :BILLINGFREQUENCY => "30",
46
+ :AMT => "9.00", # two-decimals for cents, whole number for whole currency, like a Euro or Dollar
47
+ :CURRENCYCODE => "EUR",
48
+
49
+ # termination
50
+ :TOTALBILLINGCYCLES => "0", # optional field, '0' value makes profile last forever
51
+ :MAXFAILEDPAYMENTS => "3",
52
+ :AUTOBILLAMT => "AddToNextBilling",
53
+
54
+ # Digital goods fields
55
+ :L_PAYMENTREQUEST_0_ITEMCATEGORY0 => "Digital",
56
+ :L_PAYMENTREQUEST_0_NAME0 => "Cat Clip Collection",
57
+ :L_PAYMENTREQUEST_0_AMT0 => "9.00",
58
+ :L_PAYMENTREQUEST_0_QTY0 => "1",
59
+ }
60
+
61
+ recurring_profile = Paypal::Payment::Recurring.new(raw: params)
62
+ ```
63
+
64
+ ## Note on Patches/Pull Requests
65
+
66
+ * Fork the project.
67
+ * Make your feature addition or bug fix.
68
+ * Add tests for it. This is important so I don't break it in a
69
+ future version unintentionally.
70
+ * Commit, do not mess with rakefile, version, or history.
71
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
72
+ * Send me a pull request. Bonus points for topic branches.
73
+
18
74
  ## Copyright
19
75
 
20
76
  Copyright (c) 2011 nov matake. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1.dev2
1
+ 1.1.0
@@ -83,5 +83,3 @@ require 'paypal/payment/recurring'
83
83
  require 'paypal/payment/recurring/activation'
84
84
  require 'paypal/payment/recurring/billing'
85
85
  require 'paypal/payment/recurring/summary'
86
-
87
- CreativePaypalExpress = Paypal
@@ -34,9 +34,9 @@ module Paypal
34
34
  params.merge! payment_request.to_params(index)
35
35
  end
36
36
 
37
- response = self.request(:SetExpressCheckout, params)
37
+ response = request(:SetExpressCheckout, params)
38
38
 
39
- Response.new(response, options)
39
+ Response.new response, options
40
40
  end
41
41
 
42
42
  def details(token)
@@ -90,11 +90,6 @@ module Paypal
90
90
  :TOKEN => token
91
91
  }
92
92
  params.merge!(recurring_profile.to_params)
93
-
94
- puts "== DEBUGGING PAYPAL Request#subscribe! =="
95
- puts "about to make a request to PayPal with :CreateRecurringPaymentsProfile and params:\n#{params}"
96
- puts "=========================================="
97
-
98
93
  response = self.request(:CreateRecurringPaymentsProfile, params)
99
94
  Response.new(response)
100
95
  end
@@ -103,8 +98,8 @@ module Paypal
103
98
  params = {
104
99
  :PROFILEID => profile_id
105
100
  }
106
- response = self.request(:GetRecurringPaymentsProfileDetails, params)
107
- Response.new(response)
101
+ response = self.request :GetRecurringPaymentsProfileDetails, params
102
+ Response.new response
108
103
  end
109
104
 
110
105
  def renew!(profile_id, action, options = {})
@@ -115,7 +110,8 @@ module Paypal
115
110
  if options[:note]
116
111
  params[:NOTE] = options[:note]
117
112
  end
118
- response = self.request :ManageRecurringPaymentsProfileStatus, params
113
+
114
+ response = request(:ManageRecurringPaymentsProfileStatus, params)
119
115
  Response.new response
120
116
  end
121
117
 
@@ -131,6 +127,7 @@ module Paypal
131
127
  renew!(profile_id, :Reactivate, options)
132
128
  end
133
129
 
130
+
134
131
  # Reference Transaction Specific
135
132
 
136
133
  def agree!(token, options = {})
@@ -174,8 +171,8 @@ module Paypal
174
171
  Response.new response
175
172
  end
176
173
 
177
- # Refund Specific
178
174
 
175
+ #== Refund Specific
179
176
  def refund!(transaction_id, options = {})
180
177
  params = {
181
178
  :TRANSACTIONID => transaction_id,
@@ -13,11 +13,6 @@ module Paypal
13
13
  # :VERSION=>"66.0"
14
14
  # }
15
15
  def initialize(response, options = {})
16
- puts "== DEBUGGING PAYPAL Response#initialize =="
17
- puts "response:\n#{response}"
18
- puts "options:\n#{options}"
19
- puts "=========================================="
20
-
21
16
  super response
22
17
  @pay_on_paypal = options[:pay_on_paypal]
23
18
  @mobile = options[:mobile]
@@ -41,25 +41,36 @@ module Paypal
41
41
 
42
42
  private
43
43
 
44
- def post(method, params)
45
- rest_params = common_params.merge(params).merge(METHOD: method)
46
- RestClient.post(self.class.endpoint, rest_params)
47
- end
44
+ def post(method, params)
45
+ rest_params = common_params.merge(params).merge(METHOD: method)
46
+
47
+ response = RestClient.post(self.class.endpoint, rest_params)
48
+
49
+ puts ">> Paypal::NVP Got response to POST request <<"
50
+ puts "Request arguments:\nendpoint: #{self.class.endpoint}\nparams: #{rest_params})\n"
51
+ puts "Response string:\n#{response}"
52
+ puts "=============================================="
48
53
 
49
- def handle_response
50
- response = yield
51
- response = CGI.parse(response).inject({}) do |res, (k, v)|
52
- res.merge!(k.to_sym => v.first)
54
+ return response
53
55
  end
54
- case response[:ACK]
55
- when 'Success', 'SuccessWithWarning'
56
- response
57
- else
58
- raise Exception::APIError.new(response)
56
+
57
+ def handle_response
58
+ response = yield
59
+ response = CGI.parse(response).inject({}) do |res, (k, v)|
60
+ res.merge!(k.to_sym => v.first)
61
+ end
62
+
63
+ case response[:ACK]
64
+ when 'Success', 'SuccessWithWarning'
65
+ response
66
+ else
67
+ raise Exception::APIError.new(response)
68
+ end
69
+
70
+ rescue RestClient::Exception => e
71
+ raise Exception::HttpError.new(e.http_code, e.message, e.http_body)
59
72
  end
60
- rescue RestClient::Exception => e
61
- raise Exception::HttpError.new(e.http_code, e.message, e.http_body)
62
- end
73
+
63
74
  end
64
75
  end
65
76
  end
@@ -2,6 +2,7 @@ module Paypal
2
2
  module NVP
3
3
  class Response < Base
4
4
  cattr_reader :attribute_mapping
5
+
5
6
  @@attribute_mapping = {
6
7
  :ACK => :ack,
7
8
  :BUILD => :build,
@@ -36,6 +37,7 @@ module Paypal
36
37
  :INVNUM => :invoice_number,
37
38
  :CUSTOM => :custom
38
39
  }
40
+
39
41
  attr_accessor *@@attribute_mapping.values
40
42
  attr_accessor :shipping_options_is_default, :success_page_redirect_requested, :insurance_option_selected
41
43
  attr_accessor :amount, :description, :ship_to, :bill_to, :payer, :recurring, :billing_agreement, :refund
@@ -43,6 +45,8 @@ module Paypal
43
45
  alias_method :colleration_id, :correlation_id # NOTE: I made a typo :p
44
46
 
45
47
  def initialize(attributes = {})
48
+ @raw_response = attributes
49
+
46
50
  attrs = attributes.dup
47
51
  @@attribute_mapping.each do |key, value|
48
52
  self.send "#{value}=", attrs.delete(key)
@@ -228,6 +232,10 @@ module Paypal
228
232
  Paypal.log "Ignored Parameter (#{self.class}): #{key}=#{value}", :warn
229
233
  end
230
234
  end
235
+
236
+ def to_s
237
+ return @raw_response.to_s
238
+ end
231
239
  end
232
240
  end
233
241
  end
@@ -4,40 +4,56 @@ module Paypal
4
4
  attr_optional :start_date, :description, :identifier, :status, :name, :reference, :max_fails, :auto_bill, :aggregate_amount, :aggregate_optional_amount, :final_payment_date
5
5
  attr_accessor :activation, :billing, :regular_billing, :summary
6
6
 
7
+ MANDATORY_PARAMETERS = [:DESC, :PROFILESTARTDATE, :BILLINGPERIOD, :BILLINGFREQUENCY, :AMT, :CURRENCYCODE].freeze
8
+
7
9
  def initialize(attributes = {})
8
10
  super
9
- @activation = Activation.new attributes[:activation] if attributes[:activation]
10
- @billing = Billing.new attributes[:billing] if attributes[:billing]
11
- @regular_billing = Billing.new attributes[:regular_billing] if attributes[:regular_billing]
12
- @summary = Summary.new attributes[:summary] if attributes[:summary]
11
+ @activation = Activation.new(attributes[:activation]) if attributes[:activation]
12
+ @billing = Billing.new(attributes[:billing]) if attributes[:billing]
13
+ @regular_billing = Billing.new(attributes[:regular_billing]) if attributes[:regular_billing]
14
+ @summary = Summary.new(attributes[:summary]) if attributes[:summary]
15
+ @raw_parameters = attributes[:raw].presence || {}
16
+ @parameters = build_parameters_hash
17
+
18
+ # can not make this happen as profile object is used both in cretion, response verification and status checks, which vary in available parameters
19
+ # makes sure key params have been passed one way or the other
20
+ # missing_mandatory_parameters = MANDATORY_PARAMETERS.map{|param| @parameters[param].present? ? nil : param}.compact
21
+ # raise ArgumentError.new("Missing mandatory parameters #{missing_mandatory_parameters.to_s}") if missing_mandatory_parameters.any?
13
22
  end
14
23
 
15
24
  def to_params
16
- params = [
17
- self.billing,
18
- self.activation
19
- ].compact.inject({}) do |params, attribute|
20
- params.merge! attribute.to_params
21
- end
22
- if self.start_date.is_a?(Time)
23
- self.start_date = self.start_date.to_s(:db)
24
- end
25
- params.merge!(
26
- :DESC => self.description,
27
- :MAXFAILEDPAYMENTS => self.max_fails,
28
- :AUTOBILLOUTAMT => self.auto_bill,
29
- :PROFILESTARTDATE => self.start_date,
30
- :SUBSCRIBERNAME => self.name,
31
- :PROFILEREFERENCE => self.reference
32
- )
33
- params.delete_if do |k, v|
34
- v.blank?
35
- end
25
+ return @parameters
36
26
  end
37
27
 
38
28
  def numeric_attribute?(key)
39
29
  super || [:max_fails, :failed_count].include?(key)
40
30
  end
31
+
32
+ protected
33
+ def build_parameters_hash
34
+ params = [
35
+ self.billing,
36
+ self.activation
37
+ ].compact.inject({}) do |params, attribute|
38
+ params.merge! attribute.to_params
39
+ end
40
+
41
+ params.merge!(
42
+ :DESC => self.description,
43
+ :MAXFAILEDPAYMENTS => self.max_fails,
44
+ :AUTOBILLOUTAMT => self.auto_bill,
45
+ :PROFILESTARTDATE => (start_date.is_a?(Time) ? start_date.to_s(:db) : start_date),
46
+ :SUBSCRIBERNAME => self.name,
47
+ :PROFILEREFERENCE => self.reference
48
+ )
49
+
50
+ # allows passing raw keys overriding named assignment methods
51
+ params.merge!(@raw_parameters)
52
+
53
+ return params.delete_if do |k, v|
54
+ v.blank?
55
+ end
56
+ end
41
57
  end
42
58
  end
43
- end
59
+ end
@@ -1 +1 @@
1
- PROFILEID=I%2dL8N58XFUCET3&PROFILESTATUS=ActiveProfile&TIMESTAMP=2011%2d02%2d08T07%3a17%3a51Z&CORRELATIONID=7d2e125f5ca63&ACK=Success&VERSION=66%2e0&BUILD=1704252
1
+ PROFILEID=I%2dL8N58XFUCET3&PROFILESTATUS=ActiveProfile&TIMESTAMP=2011%2d02%2d08T07%3a17%3a51Z&CORRELATIONID=7d2e125f5ca63&ACK=Success&VERSION=66%2e0&BUILD=1704252
@@ -1,4 +1,5 @@
1
- # rspec spec/paypal/express/request_spec.rb
1
+ require 'spec_helper.rb'
2
+
2
3
  describe Paypal::Express::Request do
3
4
  class Paypal::Express::Request
4
5
  attr_accessor :_sent_params_, :_method_
@@ -67,7 +68,8 @@ describe Paypal::Express::Request do
67
68
  :period => :Month,
68
69
  :frequency => 1,
69
70
  :amount => 1000
70
- }
71
+ },
72
+ raw: {:CURRENCYCODE => "EUR"},
71
73
  )
72
74
  end
73
75
 
@@ -368,20 +370,21 @@ describe Paypal::Express::Request do
368
370
  describe '#subscribe!' do
369
371
  it 'should return Paypal::Express::Response' do
370
372
  fake_response 'CreateRecurringPaymentsProfile/success'
371
- response = instance.subscribe! 'token', recurring_profile
373
+ response = instance.subscribe!('token', recurring_profile)
372
374
  response.should be_instance_of Paypal::Express::Response
373
375
  end
374
376
 
375
377
  it 'should call CreateRecurringPaymentsProfile' do
376
378
  expect do
377
- instance.subscribe! 'token', recurring_profile
378
- end.to request_to nvp_endpoint, :post
379
+ instance.subscribe!('token', recurring_profile)
380
+ end.to request_to(nvp_endpoint, :post)
379
381
  instance._method_.should == :CreateRecurringPaymentsProfile
380
382
  instance._sent_params_.should == {
381
383
  :DESC => 'Recurring Profile',
382
384
  :TOKEN => 'token',
383
385
  :SHIPPINGAMT => '0.00',
384
386
  :AMT => '1000.00',
387
+ :CURRENCYCODE => "EUR",
385
388
  :BILLINGFREQUENCY => 1,
386
389
  :MAXFAILEDPAYMENTS => 0,
387
390
  :BILLINGPERIOD => :Month,
@@ -432,7 +435,7 @@ describe Paypal::Express::Request do
432
435
  describe '#cancel!' do
433
436
  it 'should return Paypal::Express::Response' do
434
437
  fake_response 'ManageRecurringPaymentsProfileStatus/success'
435
- response = instance.cancel! 'profile_id'
438
+ response = instance.cancel!('profile_id')
436
439
  response.should be_instance_of(Paypal::Express::Response)
437
440
  end
438
441
 
@@ -1,5 +1,4 @@
1
- require 'spec_helper.rb'
2
-
1
+ # rspec spec/paypal/nvp/response_spec.rb
3
2
  describe Paypal::NVP::Response do
4
3
  let(:return_url) { 'http://example.com/success' }
5
4
  let(:cancel_url) { 'http://example.com/cancel' }
@@ -143,4 +142,17 @@ describe Paypal::NVP::Response do
143
142
  end
144
143
  end
145
144
  end
146
- end
145
+
146
+ describe "#to_s" do
147
+ before do
148
+ fake_response 'SetExpressCheckout/success'
149
+ end
150
+
151
+ it "should return a stringified hash of POST request response that instantiated the object" do
152
+ response = request.setup(payment_request, return_url, cancel_url)
153
+
154
+ expect(response.to_s).to eq("{:ACK=>\"Success\", :BUILD=>\"1721431\", :CORRELATIONID=>\"5549ea3a78af1\", :TIMESTAMP=>\"2011-02-02T02:02:18Z\", :TOKEN=>\"EC-5YJ90598G69065317\", :VERSION=>\"66.0\"}")
155
+ end
156
+ end
157
+
158
+ end
@@ -1,6 +1,7 @@
1
- require 'spec_helper.rb'
2
-
1
+ # rspec spec/paypal/payment/recurring_spec.rb
3
2
  describe Paypal::Payment::Recurring do
3
+ klass = Paypal::Payment::Recurring
4
+
4
5
  let :keys do
5
6
  Paypal::Payment::Recurring.optional_attributes
6
7
  end
@@ -56,10 +57,28 @@ describe Paypal::Payment::Recurring do
56
57
  end
57
58
 
58
59
  let :instance do
59
- Paypal::Payment::Recurring.new attributes
60
+ klass.new(attributes)
60
61
  end
61
62
 
62
63
  describe '.new' do
64
+ # can not make this happen as profile object is used both in cretion, response verification and status checks, which vary in available parameters
65
+ xit "should raise if attempting to initialize with missing mandatory parameters" do
66
+ expect{klass.new({raw: {:DESC => "test description"}})}.to raise_error(ArgumentError, /\AMissing mandatory parameters \[:PROFILESTARTDATE, :BILLINGPERIOD, :BILLINGFREQUENCY, :AMT, :CURRENCYCODE\]/)
67
+ end
68
+
69
+ xit "should not raise if initializing with all mandatory parameters" do
70
+ mandatory_parameters = {
71
+ :DESC => "Funny Movie Clips Subscription",
72
+ :PROFILESTARTDATE => "2017-01-25T15:00:00Z",
73
+ :BILLINGPERIOD => "Day", # "Month", "Year"
74
+ :BILLINGFREQUENCY => "30",
75
+ :AMT => "9.00", # two-decimals for cents, whole number for whole currency, like a Euro or Dollar
76
+ :CURRENCYCODE => "EUR",
77
+ }
78
+
79
+ expect{klass.new(raw: mandatory_parameters)}.to_not raise_error(ArgumentError)
80
+ end
81
+
63
82
  it 'should accept all supported attributes' do
64
83
  instance.identifier.should == '12345'
65
84
  instance.description.should == 'Subscription Payment Profile'
@@ -80,6 +99,7 @@ describe Paypal::Payment::Recurring do
80
99
  :tax_amount => '0'
81
100
  }
82
101
  end
102
+
83
103
  it 'should setup trial billing info' do
84
104
  instance.billing.trial.should == Paypal::Payment::Recurring::Billing.new(trial_attributes)
85
105
  end
@@ -104,11 +124,14 @@ describe Paypal::Payment::Recurring do
104
124
  }
105
125
  end
106
126
 
107
- context 'when start_date is Time' do
108
- it 'should be stringfy' do
109
- instance = Paypal::Payment::Recurring.new attributes.merge(
110
- :start_date => Time.utc(2011, 2, 8, 15, 0, 0)
127
+ context 'when start_date is a Time object' do
128
+ it 'should get correctly stringfied when converting to params' do
129
+ instance = Paypal::Payment::Recurring.new(
130
+ attributes.merge(
131
+ :start_date => Time.utc(2011, 2, 8, 15, 0, 0)
132
+ )
111
133
  )
134
+
112
135
  instance.start_date.should be_instance_of(Time)
113
136
  instance.to_params[:PROFILESTARTDATE].should == '2011-02-08 15:00:00'
114
137
  end
@@ -126,6 +149,7 @@ describe Paypal::Payment::Recurring do
126
149
  :tax_amount => '0'
127
150
  }
128
151
  end
152
+
129
153
  it 'should setup trial billing info' do
130
154
  instance.to_params.should == {
131
155
  :TRIALBILLINGPERIOD => "Month",
@@ -150,6 +174,43 @@ describe Paypal::Payment::Recurring do
150
174
  }
151
175
  end
152
176
  end
177
+
178
+ context "when attempting to initialize a Recurring Profile with an initial payment now and same payments every month" do
179
+ it "should return correct request parameters hash" do
180
+ @attributes = expected_recurring_profile_parameters
181
+
182
+ profile = Paypal::Payment::Recurring.new(raw: @attributes)
183
+
184
+ @exp = expected_recurring_profile_parameters
185
+
186
+ expect(profile.to_params).to eq @exp
187
+ end
188
+ end
189
+
190
+ context "when attempting to initialize a Recurring Profile with a large initial payment now and smaller payments every month" do
191
+ it "should return correct request parameters hash" do
192
+ @attributes = mandatory_profile_parameters.merge(initial_payment_profile_parameters).merge(auxilary_profile_parameters).merge(:INITAMT => "100.00", :AMT => "1.50")
193
+
194
+ profile = Paypal::Payment::Recurring.new(raw: @attributes)
195
+
196
+ @exp = mandatory_profile_parameters.merge(initial_payment_profile_parameters).merge(auxilary_profile_parameters).merge(:INITAMT => "100.00", :AMT => "1.50")
197
+
198
+ expect(profile.to_params).to eq @exp
199
+ end
200
+ end
201
+
202
+ context "when attempting to initialize a Recurring Profile with no initial payment and recurring payments every month starting in a week" do
203
+ it "should return correct request parameters hash" do
204
+ @attributes = mandatory_profile_parameters.merge(trial_profile_parameters).merge(auxilary_profile_parameters)
205
+
206
+ profile = Paypal::Payment::Recurring.new(raw: @attributes)
207
+
208
+ @exp = mandatory_profile_parameters.merge(trial_profile_parameters).merge(auxilary_profile_parameters)
209
+
210
+ expect(profile.to_params).to eq @exp
211
+ end
212
+ end
213
+
153
214
  end
154
215
 
155
216
  describe '#numeric_attribute?' do
@@ -167,4 +228,4 @@ describe Paypal::Payment::Recurring do
167
228
  end
168
229
  end
169
230
  end
170
- end
231
+ end
@@ -24,3 +24,80 @@ def sandbox_mode(&block)
24
24
  ensure
25
25
  Paypal.sandbox = false
26
26
  end
27
+
28
+ def expected_recurring_profile_parameters(options={})
29
+
30
+ # optional initial payment parameters
31
+ # :INITAMT => "9.00",
32
+ # :FAILEDINITAMTACTION => "CancelOnFailure", # or "ContinueOnFailure"
33
+ #
34
+ # # optional trial parameters
35
+ # :TRIALBILLINGPERIOD => "Day",
36
+ # :TRIALBILLINGFREQUENCY => "7",
37
+ # :TRIALAMT => "0.00",
38
+ # :TRIALCURRENCYCODE => "EUR",
39
+ # :TRIALTOTALBILLINGCYCLES => "1",
40
+ #
41
+ # # mandatory regular recurring profile parameters
42
+ # :DESC => "Funny Movie Clips Subscription",
43
+ # :PROFILESTARTDATE => "2017-01-25T15:00:00Z",
44
+ # :BILLINGPERIOD => "Day", # "Month", "Year"
45
+ # :BILLINGFREQUENCY => "30",
46
+ # :AMT => "9.00", # two-decimals for cents, whole number for whole currency, like a Euro or Dollar
47
+ # :CURRENCYCODE => "EUR",
48
+ #
49
+ # # termination
50
+ # :TOTALBILLINGCYCLES => "0", # optional field, '0' value makes profile last forever
51
+ # :MAXFAILEDPAYMENTS => "3",
52
+ # :AUTOBILLAMT => "AddToNextBilling",
53
+ #
54
+ # # Digital goods fields
55
+ # :L_PAYMENTREQUEST_0_ITEMCATEGORY0 => "Digital",
56
+ # :L_PAYMENTREQUEST_0_NAME0 => "Cat Clip Collection",
57
+ # :L_PAYMENTREQUEST_0_AMT0 => "9.00",
58
+ # :L_PAYMENTREQUEST_0_QTY0 => "1",
59
+ return mandatory_profile_parameters.merge(trial_profile_parameters).merge(initial_payment_profile_parameters).merge(auxilary_profile_parameters).merge(options)
60
+ end
61
+
62
+ def mandatory_profile_parameters(options={})
63
+ return {
64
+ :DESC => "Funny Movie Clips Subscription",
65
+ :PROFILESTARTDATE => "2017-01-25T15:00:00Z",
66
+ :BILLINGPERIOD => "Day", # "Month", "Year"
67
+ :BILLINGFREQUENCY => "30",
68
+ :AMT => "9.00", # two-decimals for cents, whole number for whole currency, like a Euro or Dollar
69
+ :CURRENCYCODE => "EUR",
70
+ }.merge(options)
71
+ end
72
+
73
+ def trial_profile_parameters(options={})
74
+ return {
75
+ # optional trial parameters
76
+ :TRIALBILLINGPERIOD => "Day",
77
+ :TRIALBILLINGFREQUENCY => "7",
78
+ :TRIALAMT => "0.00",
79
+ :TRIALCURRENCYCODE => "EUR",
80
+ :TRIALTOTALBILLINGCYCLES => "1",
81
+ }.merge(options)
82
+ end
83
+
84
+ def initial_payment_profile_parameters(options={})
85
+ return {
86
+ # optional initial payment parameters
87
+ :INITAMT => "9.00",
88
+ :FAILEDINITAMTACTION => "CancelOnFailure", # or "ContinueOnFailure"
89
+ }.merge(options)
90
+ end
91
+
92
+ def auxilary_profile_parameters(options={})
93
+ return {
94
+ :TOTALBILLINGCYCLES => "0", # optional field, '0' value makes profile last forever
95
+ :MAXFAILEDPAYMENTS => "3",
96
+ :AUTOBILLAMT => "AddToNextBilling",
97
+
98
+ :L_PAYMENTREQUEST_0_ITEMCATEGORY0 => "Digital",
99
+ :L_PAYMENTREQUEST_0_NAME0 => "Cat Clip Collection",
100
+ :L_PAYMENTREQUEST_0_AMT0 => "9.00",
101
+ :L_PAYMENTREQUEST_0_QTY0 => "1",
102
+ }.merge(options)
103
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: creative-paypal-express
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1.dev2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nov matake
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-11-15 00:00:00.000000000 Z
12
+ date: 2017-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport