Skip to content

Commit

Permalink
Merge remote branch 'railwaymen/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
MattG committed Sep 20, 2010
2 parents 4bec4c2 + 102cab1 commit 0cc129a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 12 deletions.
37 changes: 30 additions & 7 deletions lib/active_merchant/billing/gateways/paypal_adaptive_payment.rb
Expand Up @@ -38,7 +38,11 @@ def initialize(options = {})

def pay(options)
commit 'Pay', build_adaptive_payment_pay_request(options)
end
end

def execute_payment(options)
commit 'ExecutePayment', build_adaptive_payment_execute_request(options)
end

def details_for_payment options
commit 'PaymentDetails', build_adaptive_payment_details_request(options)
Expand Down Expand Up @@ -95,7 +99,7 @@ def build_adaptive_payment_pay_request opts
x.detailLevel 'ReturnAll'
x.errorLanguage opts[:error_language] ||= 'en_US'
end
x.actionType 'PAY'
x.actionType opts[:pay_primary] ? 'PAY_PRIMARY' : 'PAY'
x.cancelUrl opts[:cancel_url]
x.returnUrl opts[:return_url]
if opts[:notify_url]
Expand All @@ -105,6 +109,9 @@ def build_adaptive_payment_pay_request opts
x.memo opts[:memo] if opts[:memo]
x.pin opts[:pin] if opts[:pin]
x.currencyCode opts[:currency_code] ||= 'USD'
if opts[:sender_email]
x.senderEmail opts[:sender_email]
end
x.receiverList do |x|
opts[:receiver_list].each do |receiver|
x.receiver do |x|
Expand All @@ -119,6 +126,19 @@ def build_adaptive_payment_pay_request opts
x.feesPayer opts[:fees_payer] ||= 'EACHRECEIVER'
end
end

def build_adaptive_payment_execute_request opts
@xml = ''
xml = Builder::XmlMarkup.new :target => @xml, :indent => 2
xml.instruct!
xml.ExecutePaymentRequest do |x|
x.requestEnvelope do |x|
x.detailLevel 'ReturnAll'
x.errorLanguage opts[:error_language] ||= 'en_US'
end
x.payKey opts[:paykey]
end
end

def build_adaptive_payment_details_request opts
@xml = ''
Expand Down Expand Up @@ -152,8 +172,6 @@ def build_adaptive_refund_details options
if options[:tracking_id]
x.trackingId options[:tracking_id]
end
x.cancelUrl options[:cancel_url]
x.returnUrl options[:return_url]
x.currencyCode options[:currency_code] ||= 'USD'
x.receiverList do |x|
options[:receiver_list].each do |receiver|
Expand All @@ -166,7 +184,6 @@ def build_adaptive_refund_details options
end
end
end
x.feesPayer opts[:fees_payer] ||= 'EACHRECEIVER'
end
end

Expand All @@ -187,12 +204,18 @@ def build_preapproval_payment options
end

# required preapproval fields
x.endingDate opts[:end_date].strftime("%Y-%m-%dT%H%%3a%M%%3a%S")
x.startingDate opts[:start_date].strftime("%Y-%m-%dT%H%%3a%M%%3a%S")
x.endingDate opts[:end_date].strftime("%Y-%m-%dT%H:%M:%S%Z")
x.startingDate opts[:start_date].strftime("%Y-%m-%dT%H:%M:%S%Z")
x.maxTotalAmountOfAllPayments opts[:max_amount]
x.currencyCode opts[:currency_code]
x.cancelUrl opts[:cancel_url]
x.returnUrl opts[:return_url]

#optional preapproval fields
x.maxAmountPerPayment opts[:max_amount_per_payment] unless opts[:max_amount_per_payment].blank?
x.maxNumberOfPayments opts[:max_number_of_payments] unless opts[:max_number_of_payments].blank?
x.memo opts[:memo] unless opts[:memo].blank?


# notify url
if opts[:notify_url]
Expand Down
Expand Up @@ -4,19 +4,26 @@ module AdaptivePaymentResponses

class AdaptivePaypalSuccessResponse

REDIRECT_URL = 'https://www.paypal.com/webscr?cmd=_ap-payment&paykey='
TEST_REDIRECT_URL = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-payment&paykey='
BASE_REDIRECT_URL = 'https://www.paypal.com/webscr?cmd='
TEST_BASE_REDIRECT_URL = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd='
PAY_COMMAND = '_ap-payment&paykey='
PREAPPROVAL_COMMAND = '_ap-preapproval&preapprovalkey='

attr_reader :paykey
attr_reader :paykey, :preapprovalkey

def initialize json

@paykey = json['payKey']
@preapprovalkey = json['preapprovalKey']
@params = json
end

def redirect_url_for
Base.gateway_mode == :test ? (TEST_REDIRECT_URL + @paykey) : (REDIRECT_URL + @paykey)
(Base.gateway_mode == :test ? TEST_BASE_REDIRECT_URL : BASE_REDIRECT_URL) + PAY_COMMAND + @paykey
end

def redirect_preapproval_url_for
(Base.gateway_mode == :test ? TEST_BASE_REDIRECT_URL : BASE_REDIRECT_URL) + PREAPPROVAL_COMMAND + @preapprovalkey
end

def ack
Expand All @@ -40,6 +47,22 @@ def status
@params['status']
end

def refund_status
@params["refundInfoList"]["refundInfo"].first["refundStatus"]
end

def execute_status
@params['paymentExecStatus']
end

def refund_complete?
refund_status == 'REFUNDED' || refund_status == 'ALREADY_REVERSED_OR_REFUNDED'
end

def execute_complete?
execute_status == 'COMPLETED'
end

end

class AdaptivePaypalErrorResponse
Expand All @@ -56,4 +79,4 @@ def debug

end
end
end
end

0 comments on commit 0cc129a

Please sign in to comment.