Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Add displayOptions and receiverOptions support to SetPaymentOptionsRequest #19

Merged
merged 4 commits into from almost 2 years ago

2 participants

Niels Ganser Jose Pablo Barrantes
Niels Ganser

i.a., this allows one to set invoice item details and custom logos.

See pp. 147-153 of https://cms.paypal.com/cms_content/US/en_US/files/developer/PP_AdaptivePayments.pdf for more info.

Jose Pablo Barrantes
Owner

Thanks! <3<3<3

Jose Pablo Barrantes jpablobr merged commit 597ecad into from May 01, 2012
Jose Pablo Barrantes jpablobr closed this May 01, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
52  README.md
Source Rendered
@@ -9,7 +9,7 @@ This library is meant to interface with PayPal's Adaptive Payment Gateway.
9 9
 ## Supported
10 10
 
11 11
 * Payments
12  
-* Peapprovals
  12
+* Preapprovals
13 13
 * Refunds
14 14
 * Currency conversions
15 15
 * getting/setting payment options
@@ -37,7 +37,7 @@ See [iAuction: An Adaptive Payments Tutorial Featuring Parallel Payments](https:
37 37
       :signature => "Abg0gYcQlsdkls2HDJkKtA-p6pqhA1k-KTYE0Gcy1diujFio4io5Vqjf",
38 38
       :appid => "APP-80W284485P519543T" )
39 39
 
40  
-### Pre-approved paymen
  40
+### Pre-approved payment
41 41
 
42 42
     gateway.preapprove_payment (
43 43
       :return_url => "returnURL",
@@ -91,6 +91,54 @@ end
91 91
 ActiveMerchant::Billing::Base.mode = :test
92 92
 ```
93 93
 
  94
+### Setting advanced payment and invoice options
  95
+
  96
+To be able to set additional payment and invoice options, such as item names,
  97
+shipping costs, custom logos, etc., you must first create a payment, then set
  98
+the options and then direct the user to the payment page:
  99
+
  100
+```ruby
  101
+purchase = gateway.setup_purchase(
  102
+  :action_type => "CREATE", # This is in contrast to the default PAY action
  103
+  …                         # as above
  104
+)
  105
+
  106
+gateway.set_payment_options(
  107
+  :display_options => {
  108
+    :business_name    => "Your Business",
  109
+    :header_image_url => "http://cdn.yourbusiness.com/logo-for-paypal.png"
  110
+  },
  111
+  :pay_key => purchase["payKey"],
  112
+  :receiver_options => [
  113
+    {
  114
+      :description => "Your purchase of XYZ",
  115
+      :invoice_data => {
  116
+        :item => [
  117
+          { :name => "Item #1", :item_count => 1, :item_price => 100, :price => 100 },
  118
+          { :name => "Item #2", :item_count => 2, :item_price => 10, :price => 20 }
  119
+        ],
  120
+        :total_shipping => 5,
  121
+        :total_tax => 10
  122
+      },
  123
+      :receiver => { :email => "receiver1@example.com" }
  124
+    },
  125
+    {
  126
+      :description => "XYZ Processing fee",
  127
+      :invoice_data => {
  128
+        :item => [{ :name => "Fee", :item_count => 1, :item_price => 10, :price => 10 }]
  129
+      },
  130
+      :receiver => { :email => "receiver2@example.com" }
  131
+    }
  132
+  ]
  133
+)
  134
+
  135
+redirect_to(gateway.redirect_url_for(purchase["payKey"]))
  136
+```
  137
+
  138
+See the implementation of ActiveMerchant::Billing::PaypalAdaptivePayment#build_adaptive_set_payment_options_request
  139
+for all available options and [Operation SetPaymentOptions API](https://cms.paypal.com/cms_content/US/en_US/files/developer/PP_AdaptivePayments.pdf)
  140
+for a description of them.
  141
+
94 142
 ## Testing
95 143
 
96 144
 First modify the `test/fixtures.yml` to fit your app credentials (You
40  lib/active_merchant/billing/gateways/paypal_adaptive_payment.rb
@@ -207,6 +207,46 @@ def build_adaptive_set_payment_options_request(opts)
207 207
             x.requireShippingAddressSelection opts[:sender][:require_shipping_address_selection] if opts[:sender][:require_shipping_address_selection]
208 208
             x.referrerCode opts[:sender][:referrerCode] if opts[:sender][:referrerCode]
209 209
           end
  210
+          unless opts[:display_options].blank?
  211
+            x.displayOptions do |x|
  212
+              x.emailHeaderImageUrl opts[:display_options][:email_header_image_url] if opts[:display_options][:email_header_image_url]
  213
+              x.emailMarketingImageUrl opts[:display_options][:email_marketing_image_url] if opts[:display_options][:email_marketing_image_url]
  214
+              x.headerImageUrl opts[:display_options][:header_image_url] if opts[:display_options][:header_image_url]
  215
+              x.businessName opts[:display_options][:business_name] if opts[:display_options][:business_name]
  216
+            end
  217
+          end
  218
+          opts[:receiver_options].try(:each) do |receiver_options|
  219
+            x.receiverOptions do |x|
  220
+              x.description receiver_options[:description] if receiver_options[:description]
  221
+              x.customId receiver_options[:custom_id] if receiver_options[:custom_id]
  222
+              unless receiver_options[:invoice_data].blank?
  223
+                x.invoiceData do |x|
  224
+                  receiver_options[:invoice_data][:item].try(:each) do |item|
  225
+                    x.item do |x|
  226
+                      x.name item[:name] if item[:name]
  227
+                      x.identifier item[:identifier] if item[:identifier]
  228
+                      x.price item[:price] if item[:price]
  229
+                      x.itemPrice item[:item_price] if item[:item_price]
  230
+                      x.itemCount item[:item_count] if item[:item_count]
  231
+                    end
  232
+                  end
  233
+                  x.totalTax receiver_options[:invoice_data][:total_tax] if receiver_options[:invoice_data][:total_tax]
  234
+                  x.totalShipping receiver_options[:invoice_data][:total_shipping] if receiver_options[:invoice_data][:total_shipping]
  235
+                end
  236
+              end
  237
+              x.receiver do |x|
  238
+                x.email receiver_options[:receiver][:email] if receiver_options[:receiver][:email]
  239
+                unless receiver_options[:receiver][:phone].blank?
  240
+                  x.phone do |x|
  241
+                    x.countryCode receiver_options[:receiver][:phone][:country_code]
  242
+                    x.phoneNumber receiver_options[:receiver][:phone][:phone_number]
  243
+                    x.extension receiver_options[:receiver][:phone][:extension] if receiver_options[:receiver][:phone][:extension]
  244
+                  end
  245
+                end
  246
+              end
  247
+              x.referrerCode receiver_options[:referrer_code] if receiver_options[:referrer_code]
  248
+            end
  249
+          end
210 250
           x.payKey opts[:pay_key]
211 251
         end
212 252
       end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.