Included Modules

Class Index [+]

Quicksearch

ActiveMerchant::Billing::PaypalExpressGateway

Public Instance Methods

authorize(money, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/paypal_express.rb, line 32
32:       def authorize(money, options = {})
33:         requires!(options, :token, :payer_id)
34:       
35:         commit 'DoExpressCheckoutPayment', build_sale_or_authorization_request('Authorization', money, options)
36:       end
details_for(token) click to toggle source
    # File lib/active_merchant/billing/gateways/paypal_express.rb, line 28
28:       def details_for(token)
29:         commit 'GetExpressCheckoutDetails', build_get_details_request(token)
30:       end
purchase(money, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/paypal_express.rb, line 38
38:       def purchase(money, options = {})
39:         requires!(options, :token, :payer_id)
40:         
41:         commit 'DoExpressCheckoutPayment', build_sale_or_authorization_request('Sale', money, options)
42:       end
setup_authorization(money, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/paypal_express.rb, line 16
16:       def setup_authorization(money, options = {})
17:         requires!(options, :return_url, :cancel_return_url)
18:         
19:         commit 'SetExpressCheckout', build_setup_request('Authorization', money, options)
20:       end
setup_purchase(money, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/paypal_express.rb, line 22
22:       def setup_purchase(money, options = {})
23:         requires!(options, :return_url, :cancel_return_url)
24:         
25:         commit 'SetExpressCheckout', build_setup_request('Sale', money, options)
26:       end

Private Instance Methods

add_items_xml(xml, options, currency_code) click to toggle source
     # File lib/active_merchant/billing/gateways/paypal_express.rb, line 168
168:       def add_items_xml(xml, options, currency_code)
169:         options[:items].each do |item|
170:           xml.tag! 'n2:PaymentDetailsItem' do
171:             xml.tag! 'n2:Name', item[:name]
172:             xml.tag! 'n2:Number', item[:number]
173:             xml.tag! 'n2:Quantity', item[:quantity]
174:             if item[:amount]
175:               xml.tag! 'n2:Amount', localized_amount(item[:amount], currency_code), 'currencyID' => currency_code
176:             end
177:             xml.tag! 'n2:Description', item[:description]
178:             xml.tag! 'n2:ItemURL', item[:url]
179:           end
180:         end
181:       end
build_get_details_request(token) click to toggle source
    # File lib/active_merchant/billing/gateways/paypal_express.rb, line 45
45:       def build_get_details_request(token)
46:         xml = Builder::XmlMarkup.new :indent => 2
47:         xml.tag! 'GetExpressCheckoutDetailsReq', 'xmlns' => PAYPAL_NAMESPACE do
48:           xml.tag! 'GetExpressCheckoutDetailsRequest', 'xmlns:n2' => EBAY_NAMESPACE do
49:             xml.tag! 'n2:Version', API_VERSION
50:             xml.tag! 'Token', token
51:           end
52:         end
53: 
54:         xml.target!
55:       end
build_response(success, message, response, options = {}) click to toggle source
     # File lib/active_merchant/billing/gateways/paypal_express.rb, line 162
162:       def build_response(success, message, response, options = {})
163:         PaypalExpressResponse.new(success, message, response, options)
164:       end
build_sale_or_authorization_request(action, money, options) click to toggle source
    # File lib/active_merchant/billing/gateways/paypal_express.rb, line 57
57:       def build_sale_or_authorization_request(action, money, options)
58:         currency_code = options[:currency] || currency(money)
59:         
60:         xml = Builder::XmlMarkup.new :indent => 2
61:         xml.tag! 'DoExpressCheckoutPaymentReq', 'xmlns' => PAYPAL_NAMESPACE do
62:           xml.tag! 'DoExpressCheckoutPaymentRequest', 'xmlns:n2' => EBAY_NAMESPACE do
63:             xml.tag! 'n2:Version', API_VERSION
64:             xml.tag! 'n2:DoExpressCheckoutPaymentRequestDetails' do
65:               xml.tag! 'n2:PaymentAction', action
66:               xml.tag! 'n2:Token', options[:token]
67:               xml.tag! 'n2:PayerID', options[:payer_id]
68:               xml.tag! 'n2:PaymentDetails' do
69:                 xml.tag! 'n2:OrderTotal', localized_amount(money, currency_code), 'currencyID' => currency_code
70:                 
71:                 # All of the values must be included together and add up to the order total
72:                 if [:subtotal, :shipping, :handling, :tax].all?{ |o| options.has_key?(o) }
73:                   xml.tag! 'n2:ItemTotal', localized_amount(options[:subtotal], currency_code), 'currencyID' => currency_code
74:                   xml.tag! 'n2:ShippingTotal', localized_amount(options[:shipping], currency_code),'currencyID' => currency_code
75:                   xml.tag! 'n2:HandlingTotal', localized_amount(options[:handling], currency_code),'currencyID' => currency_code
76:                   xml.tag! 'n2:TaxTotal', localized_amount(options[:tax], currency_code), 'currencyID' => currency_code
77:                 end
78:                 
79:                 xml.tag! 'n2:NotifyURL', options[:notify_url]
80:                 xml.tag! 'n2:ButtonSource', application_id.to_s.slice(0,32) unless application_id.blank?
81:                 xml.tag! 'n2:InvoiceID', options[:order_id]
82:                 xml.tag! 'n2:OrderDescription', options[:description]
83: 
84:                 add_items_xml(xml, options, currency_code) if options[:items]
85:               end
86:             end
87:           end
88:         end
89: 
90:         xml.target!
91:       end
build_setup_request(action, money, options) click to toggle source
     # File lib/active_merchant/billing/gateways/paypal_express.rb, line 93
 93:       def build_setup_request(action, money, options)
 94:         currency_code = options[:currency] || currency(money)
 95:         
 96:         xml = Builder::XmlMarkup.new :indent => 2
 97:         xml.tag! 'SetExpressCheckoutReq', 'xmlns' => PAYPAL_NAMESPACE do
 98:           xml.tag! 'SetExpressCheckoutRequest', 'xmlns:n2' => EBAY_NAMESPACE do
 99:             xml.tag! 'n2:Version', API_VERSION
100:             xml.tag! 'n2:SetExpressCheckoutRequestDetails' do
101:               if options[:max_amount]
102:                 xml.tag! 'n2:MaxAmount', localized_amount(options[:max_amount], currency_code), 'currencyID' => currency_code
103:               end
104:               if !options[:allow_note].nil?
105:                 xml.tag! 'n2:AllowNote', options[:allow_note] ? '1' : '0'
106:               end
107:               xml.tag! 'n2:PaymentDetails' do
108:                 xml.tag! 'n2:OrderTotal', amount(money).to_f.zero? ? localized_amount(100, currency_code) : localized_amount(money, currency_code), 'currencyID' => currency_code
109:                 # All of the values must be included together and add up to the order total
110:                 if [:subtotal, :shipping, :handling, :tax].all? { |o| options.has_key?(o) }
111:                   xml.tag! 'n2:ItemTotal', localized_amount(options[:subtotal], currency_code), 'currencyID' => currency_code
112:                   xml.tag! 'n2:ShippingTotal', localized_amount(options[:shipping], currency_code), 'currencyID' => currency_code
113:                   xml.tag! 'n2:HandlingTotal', localized_amount(options[:handling], currency_code), 'currencyID' => currency_code
114:                   xml.tag! 'n2:TaxTotal', localized_amount(options[:tax], currency_code), 'currencyID' => currency_code
115:                 end
116: 
117:                 xml.tag! 'n2:OrderDescription', options[:description]
118:                 xml.tag! 'n2:InvoiceID', options[:order_id]
119: 
120:                 add_items_xml(xml, options, currency_code) if options[:items]
121: 
122:                 add_address(xml, 'n2:ShipToAddress', options[:shipping_address] || options[:address])
123: 
124:                 xml.tag! 'n2:PaymentAction', action
125:               end
126: 
127:               xml.tag! 'n2:AddressOverride', options[:address_override] ? '1' : '0'
128:               xml.tag! 'n2:NoShipping', options[:no_shipping] ? '1' : '0'
129:               xml.tag! 'n2:ReturnURL', options[:return_url]
130:               xml.tag! 'n2:CancelURL', options[:cancel_return_url]
131:               xml.tag! 'n2:IPAddress', options[:ip] unless options[:ip].blank?
132:               xml.tag! 'n2:BuyerEmail', options[:email] unless options[:email].blank?
133:               
134:               if options[:billing_agreement]
135:                 xml.tag! 'n2:BillingAgreementDetails' do
136:                   xml.tag! 'n2:BillingType', options[:billing_agreement][:type]
137:                   xml.tag! 'n2:BillingAgreementDescription', options[:billing_agreement][:description]
138:                   xml.tag! 'n2:PaymentType', options[:billing_agreement][:payment_type] || 'InstantOnly'
139:                 end
140:               end
141:         
142:               # Customization of the payment page
143:               xml.tag! 'n2:PageStyle', options[:page_style] unless options[:page_style].blank?
144:               xml.tag! 'n2:cpp-header-image', options[:header_image] unless options[:header_image].blank?
145:               xml.tag! 'n2:cpp-header-back-color', options[:header_background_color] unless options[:header_background_color].blank?
146:               xml.tag! 'n2:cpp-header-border-color', options[:header_border_color] unless options[:header_border_color].blank?
147:               xml.tag! 'n2:cpp-payflow-color', options[:background_color] unless options[:background_color].blank?
148:               
149:               if options[:allow_guest_checkout]
150:                 xml.tag! 'n2:SolutionType', 'Sole'
151:                 xml.tag! 'n2:LandingPage', 'Billing'
152:               end
153:               
154:               xml.tag! 'n2:LocaleCode', options[:locale] unless options[:locale].blank?
155:             end
156:           end
157:         end
158: 
159:         xml.target!
160:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.