Skip to content

Commit 40ca39d

Browse files
committed
Added support for multiple mapping.
1 parent 337e37b commit 40ca39d

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

lib/paypal/recurring/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def checkout_details
9999
# response.completed? && response.approved?
100100
#
101101
def request_payment
102-
params = collect(:amount, :return_url, :cancel_url, :ipn_url, :currency, :description, :payer_id, :token).merge(:payment_action => "Sale")
102+
params = collect(:amount, :return_url, :cancel_url, :ipn_url, :currency, :description, :payer_id, :token, :reference).merge(:payment_action => "Sale")
103103
request.run(:payment, params)
104104
end
105105

lib/paypal/recurring/response/base.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ def self.mapping(options = {})
99
class_eval <<-RUBY
1010
def #{to}
1111
@#{to} ||= begin
12-
value = params[:#{from}]
13-
value = send("build_#{to}", params[:#{from}]) if respond_to?("build_#{to}", true)
12+
from = [#{from.inspect}].flatten
13+
name = from.find {|name| params[name]}
14+
value = nil
15+
value = params[name] if name
16+
value = send("build_#{to}", value) if respond_to?("build_#{to}", true)
1417
value
1518
end
1619
end

lib/paypal/recurring/response/payment.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ class Payment < Base
66
:status => :PAYMENTINFO_0_PAYMENTSTATUS,
77
:amount => :PAYMENTINFO_0_AMT,
88
:fees => :PAYMENTINFO_0_FEEAMT,
9-
:seller_id => :PAYMENTINFO_0_SECUREMERCHANTACCOUNTID
9+
:seller_id => :PAYMENTINFO_0_SECUREMERCHANTACCOUNTID,
10+
:reference => [:PROFILEREFERENCE, :PAYMENTREQUEST_0_CUSTOM, :PAYMENTREQUEST_0_INVNUM]
1011
)
1112

1213
def completed?

spec/paypal/response/base_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require "spec_helper"
2+
3+
describe PayPal::Recurring::Response do
4+
let(:response_class) { Class.new(PayPal::Recurring::Response::Base) }
5+
6+
describe ".mapping" do
7+
it "returns single item mapping" do
8+
response_class.mapping :foo => :bar
9+
response = response_class.new(stub(:body => "bar=foo"))
10+
response.foo.should == "foo"
11+
end
12+
13+
it "returns item from array mapping" do
14+
response_class.mapping :foo => [:bar, :zaz]
15+
response = response_class.new(stub(:body => "zaz=foo"))
16+
response.foo.should == "foo"
17+
end
18+
end
19+
end

0 commit comments

Comments
 (0)