Skip to content

Commit

Permalink
call DoReferenceTransaction from Paypal::Express::Request
Browse files Browse the repository at this point in the history
  • Loading branch information
fujimura committed Jul 19, 2011
1 parent 63f1d50 commit a6c1027
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
14 changes: 14 additions & 0 deletions lib/paypal/express/request.rb
Expand Up @@ -96,6 +96,20 @@ def refund!(transaction_id, options = {})
Response.new response
end

def reference_transaction!(billing_agreement_id, options = {})
params = {
:PAYMENTACTION => 'Sale'
}
params[:REFERENCEID] = billing_agreement_id
params[:AMT] = Util.formatted_amount(options[:amount])

params[:CURRENCYCODE] = options[:currency_code]
params[:PAYMENTACTION] = 'Sale'

response = self.request :DoReferenceTransaction, params
Response.new response
end

end
end
end
12 changes: 11 additions & 1 deletion lib/paypal/nvp/response.rb
Expand Up @@ -16,7 +16,17 @@ class Response < Base
:TIMESTAMP => :timestamp,
:TOKEN => :token,
:VERSION => :version,
:BILLINGAGREEMENTID => :billing_agreement_id
:BILLINGAGREEMENTID => :billing_agreement_id,
:PROTECTIONELIGIBILITYTYPE => :protection_eligibility_type,
:TRANSACTIONID => :transaction_id,
:ORDERTIME => :order_time,
:PENDINGREASON => :pending_reason,
:REASONCODE => :reason_code,
:TRANSACTIONTYPE => :transaction_type,
:PAYMENTSTATUS => :payment_status,
:PROTECTIONELIGIBILITY => :protection_eligibility,
:FEEAMT => :fee_amount,
:PAYMENTTYPE => :payment_type
}
attr_accessor *@@attribute_mapping.values
attr_accessor :shipping_options_is_default, :success_page_redirect_requested, :insurance_option_selected
Expand Down
1 change: 1 addition & 0 deletions spec/fake_response/DoReferenceTransaction/failure.txt
@@ -0,0 +1 @@
TIMESTAMP=2011%2d07%2d19T08%3a59%3a52Z&CORRELATIONID=ed8096a3c3d7d&ACK=Failure&VERSION=72%2e0&BUILD=1982348&L_ERRORCODE0=11451&L_SHORTMESSAGE0=Billing%20Agreement%20Id%20or%20transaction%20Id%20is%20not%20valid&L_LONGMESSAGE0=Billing%20Agreement%20Id%20or%20transaction%20Id%20is%20not%20valid&L_SEVERITYCODE0=Error&TRANSACTIONTYPE=None&PAYMENTTYPE=None&ORDERTIME=1970%2d01%2d01T00%3a00%3a00Z&PAYMENTSTATUS=None&PENDINGREASON=None&REASONCODE=None
1 change: 1 addition & 0 deletions spec/fake_response/DoReferenceTransaction/success.txt
@@ -0,0 +1 @@
BILLINGAGREEMENTID=B%2d7HU5U5U1ULU14U49E&TIMESTAMP=2011%2d07%2d19T08%3a30%3a08Z&CORRELATIONID=12ca85fb3c9d2&ACK=Success&VERSION=72%2e0&BUILD=1982348&TRANSACTIONID=3IV51111LY1211907&TRANSACTIONTYPE=merchtpmt&PAYMENTTYPE=instant&ORDERTIME=2011%2d07%2d19T08%3a30%3a06Z&AMT=192&FEEAMT=47&TAXAMT=0&CURRENCYCODE=JPY&PAYMENTSTATUS=Completed&PENDINGREASON=None&REASONCODE=None&PROTECTIONELIGIBILITY=Ineligible&PROTECTIONELIGIBILITYTYPE=None
33 changes: 32 additions & 1 deletion spec/paypal/express/request_spec.rb
Expand Up @@ -34,12 +34,19 @@ def post_with_logging(method, params)
end

let :recurring_payment_request do
Paypal::Payment::Request.new(
Paypal::Payment::Request.new(
:billing_type => :RecurringPayments,
:billing_agreement_description => 'Recurring Payment Request'
)
end

let :reference_transaction_request do
Paypal::Payment::Request.new(
:amount => 1000,
:currency_code => 'JPY'
)
end

let :recurring_profile do
Paypal::Payment::Recurring.new(
:start_date => Time.utc(2011, 2, 8, 9, 0, 0),
Expand Down Expand Up @@ -319,4 +326,28 @@ def post_with_logging(method, params)
end
end

describe '#reference_transaction!' do
it 'should return Paypal::Express::Response' do
fake_response 'DoReferenceTransaction/success'
response = instance.reference_transaction! 'billing_agreement_id', :amount => 1000, :currency_code => 'JPY'
response.should be_instance_of(Paypal::Express::Response)
end

it 'should call DoExpressCheckoutPayment' do
expect do
instance.reference_transaction!('billing_agreement_id',
:amount => 1000,
:currency_code => 'JPY',
:payment_action => 'Sale')
end.should request_to nvp_endpoint, :post
instance._method_.should == :DoReferenceTransaction
instance._sent_params_.should == {
:REFERENCEID => 'billing_agreement_id',
:AMT => '1000.00',
:CURRENCYCODE => 'JPY',
:PAYMENTACTION => 'Sale'
}
end
end

end

0 comments on commit a6c1027

Please sign in to comment.