killbill-paypal-express 4.1.4 → 4.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/NEWS +3 -0
- data/README.md +43 -2
- data/VERSION +1 -1
- data/lib/paypal_express/api.rb +100 -5
- data/pom.xml +1 -1
- data/spec/paypal_express/base_plugin_spec.rb +89 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8dc36b7724efd4b473e338fcceee7e3ea0d5bbaa
|
4
|
+
data.tar.gz: e7bbff378a81f45c74e1d289d9d573ec6d9e87f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a9e587a52da1a8d0a752fb47934649f9be28f7a532a9a1ecc9925c90f0a85e006547ce345d058ec250c4a055c092bae3428521ef3aa38b038baf3eac2797b56
|
7
|
+
data.tar.gz: 641a6f9b88cbee002bd99c4b9b5872b789395ef4a86e1a464ab3d904268d3d1ba1806e461c012790ce12bf5ab50022638a78ee842d623cadc0cd2803b7c16fd0
|
data/Gemfile.lock
CHANGED
data/NEWS
CHANGED
data/README.md
CHANGED
@@ -217,5 +217,46 @@ Plugin properties
|
|
217
217
|
| zip | Billing address zip code |
|
218
218
|
| state | Billing address state |
|
219
219
|
| country | Billing address country |
|
220
|
-
|
221
|
-
|
220
|
+
|
221
|
+
Below is a list of optional parameters for build_form_descriptor call. More details can be found on PayPal [manual](https://developer.paypal.com/docs/classic/api/merchant/SetExpressCheckout_API_Operation_SOAP/)
|
222
|
+
|
223
|
+
| Key | Description |
|
224
|
+
| ---------------------------: | ----------------------------------------------------------------- |
|
225
|
+
| max_amount | Maximum amount parameter |
|
226
|
+
| auth_mode | If true, [Authorization Payment Action](https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECRelatedAPIOps/) is adopted. Otherwise, Sale Payment Action is used.|
|
227
|
+
| no_shipping | Whether or not to show shipping address on PayPal checkout page |
|
228
|
+
| req_billing_address | Is 1 or 0. The value 1 indicates that you require that the buyer’s billing address on file with PayPal be returned. Setting this element will return `BILLTONAME`, `STREET`, `STREET2`, `CITY`, `STATE`, `ZIP`, and `COUNTRYCODE`. |
|
229
|
+
| address_override | Determines whether or not the PayPal pages should display the shipping address set by you in this SetExpressCheckout request, not the shipping address on file with PayPal for this buyer.|
|
230
|
+
| locale | Locale of pages displayed by PayPal during Express Checkout. It is either a two-letter country code or five-character locale code supported by PayPal. |
|
231
|
+
| brand_name | A label that overrides the business name in the PayPal account on the PayPal hosted checkout pages.|
|
232
|
+
| page_style | Name of the Custom Payment Page Style for payment pages associated with this button or link. It corresponds to the HTML variable page_style for customizing payment pages. |
|
233
|
+
| logo_image | A URL to your logo image. Use a valid graphics format, such as .gif, .jpg, or .png. Limit the image to 190 pixels wide by 60 pixels high. |
|
234
|
+
| header_image | URL for the image you want to appear at the top left of the payment page. The image has a maximum size of 750 pixels wide by 90 pixels high. |
|
235
|
+
| header_border_color | Sets the border color around the header of the payment page. The border is a 2-pixel perimeter around the header space, which is 750 pixels wide by 90 pixels high. By default, the color is black. |
|
236
|
+
| header_background_color | Sets the background color for the header of the payment page. By default, the color is white. |
|
237
|
+
| background_color | Sets the background color for the payment page. By default, the color is white.|
|
238
|
+
| allow_guest_checkout | If set to true, then the SolutionType is Sole and buyer does not need to create a PayPal account to check out. |
|
239
|
+
| landing_page | Type of PayPal page to display. It is one of the following values: Billing for Non-PayPal account and Login — PayPal account login. |
|
240
|
+
| email | Email address of the buyer as entered during checkout. PayPal uses this value to pre-fill the PayPal membership sign-up portion on the PayPal pages. |
|
241
|
+
| allow_note | Enables the buyer to enter a note to the merchant on the PayPal page during checkout.|
|
242
|
+
| callback_url | URL to which the callback request from PayPal is sent. It must start with HTTPS for production integration. |
|
243
|
+
| callback_timeout | An override for you to request more or less time to be able to process the callback request and respond. |
|
244
|
+
| allow_buyer_optin | Enables the buyer to provide their email address on the PayPal pages to be notified of promotions or special events. |
|
245
|
+
| shipping_address | Address to which the order is shipped. This parameter must be a JSON Hash with keys of `name`, `address1`, `address2`, `state`, `city`, `country`, `phone`, `zip` and `phone`. |
|
246
|
+
| address | Address to which the order is shipped if shipping_address is not set. This parameter must be a JSON Hash with keys of `name`, `address1`, `address2`, `state`, `city`, `country`, `phone`, `zip` and `phone`. |
|
247
|
+
| total_type | Type declaration for the label to be displayed in MiniCart for UX. It is one of the following values: Total or EstimatedTotal. |
|
248
|
+
| funding_sources | This parameter must be in a JSON hash format with a key being `source`. This element could be used to specify the preferred funding option for a guest user. However, the `landing_page` element must also be set to `Billing`. Otherwise, it is ignored.|
|
249
|
+
| shipping_options | This parameter must be in a JSON hash format with keys of `default`, `amount`, and `name`. This corresponds to the `ShippingOptionsType` in the SetupExpressCheckout call. |
|
250
|
+
| subtotal | Sum of cost of all items in this order. For digital goods, this field is required. |
|
251
|
+
| shipping | Total shipping costs for this order. |
|
252
|
+
| handling | Total handling costs for this order. |
|
253
|
+
| tax | Sum of tax for all items in this order. |
|
254
|
+
| insurance_total | Total shipping insurance costs for this order. The value must be a non-negative currency amount or null if you offer insurance options. |
|
255
|
+
| shipping_discount | Shipping discount for this order, specified as a negative number. |
|
256
|
+
| insurance_option_offered | Indicates whether insurance is available as an option the buyer can choose on the PayPal Review page. |
|
257
|
+
| description | Description of items the buyer is purchasing. |
|
258
|
+
| custom | A free-form field for your own use. |
|
259
|
+
| order_id | Your own invoice or tracking number. |
|
260
|
+
| invoice_id | Your own invoice or tracking number. This will be overridden by order_id. |
|
261
|
+
| notify_url | Your URL for receiving Instant Payment Notification (IPN) about this transaction. If you do not specify this value in the request, the notification URL from your Merchant Profile is used, if one exists.|
|
262
|
+
| items | This parameter must be a JSON Array that contains a list of Hashes with keys of `name`, `number`, `quantity`, `amount`, `description`, `url` and `category`. |
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.1.
|
1
|
+
4.1.5
|
data/lib/paypal_express/api.rb
CHANGED
@@ -318,11 +318,7 @@ module Killbill #:nodoc:
|
|
318
318
|
options[:cancel_return_url] = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, :cancel_return_url)
|
319
319
|
options[:payment_processor_account_id] = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, :payment_processor_account_id)
|
320
320
|
|
321
|
-
|
322
|
-
if max_amount_value
|
323
|
-
max_amount_in_cents = to_cents((max_amount_value || '0').to_f, currency)
|
324
|
-
options[:max_amount] = max_amount_in_cents
|
325
|
-
end
|
321
|
+
add_optional_parameters options, properties_hash, currency
|
326
322
|
|
327
323
|
amount_in_cents = amount.nil? ? nil : to_cents(amount, currency)
|
328
324
|
response = @private_api.initiate_express_checkout(kb_account_id,
|
@@ -449,6 +445,105 @@ module Killbill #:nodoc:
|
|
449
445
|
def cancel_pending_transaction(transaction_plugin_info)
|
450
446
|
@response_model.cancel_pending_payment transaction_plugin_info
|
451
447
|
end
|
448
|
+
|
449
|
+
def add_optional_parameters(options, properties_hash, currency)
|
450
|
+
[:max_amount,
|
451
|
+
:req_billing_address,
|
452
|
+
:no_shipping,
|
453
|
+
:address_override,
|
454
|
+
:locale,
|
455
|
+
:brand_name,
|
456
|
+
:page_style,
|
457
|
+
:logo_image,
|
458
|
+
:header_image,
|
459
|
+
:header_border_color,
|
460
|
+
:header_background_color,
|
461
|
+
:background_color,
|
462
|
+
:allow_guest_checkout,
|
463
|
+
:landing_page,
|
464
|
+
:email,
|
465
|
+
:allow_note,
|
466
|
+
:callback_url,
|
467
|
+
:callback_timeout,
|
468
|
+
:allow_buyer_optin,
|
469
|
+
:callback_version,
|
470
|
+
:address,
|
471
|
+
:shipping_address,
|
472
|
+
:total_type,
|
473
|
+
:funding_sources,
|
474
|
+
:shipping_options,
|
475
|
+
# Below are options for payment details
|
476
|
+
:subtotal,
|
477
|
+
:shipping,
|
478
|
+
:handling,
|
479
|
+
:tax,
|
480
|
+
:insurance_total,
|
481
|
+
:shipping_discount,
|
482
|
+
:insurance_option_offered,
|
483
|
+
:description,
|
484
|
+
:custom,
|
485
|
+
:order_id,
|
486
|
+
:invoice_id,
|
487
|
+
:notify_url,
|
488
|
+
:items].each do |sym|
|
489
|
+
option_val = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, sym)
|
490
|
+
options[sym] = option_val unless option_val.nil?
|
491
|
+
end
|
492
|
+
|
493
|
+
# Special consideration for amount related options
|
494
|
+
[:max_amount,
|
495
|
+
:subtotal,
|
496
|
+
:shipping,
|
497
|
+
:handling,
|
498
|
+
:tax,
|
499
|
+
:insurance_total,
|
500
|
+
:shipping_discount].each do |sym|
|
501
|
+
if options[sym]
|
502
|
+
options[sym] = to_cents((options[sym] || '0').to_f, currency)
|
503
|
+
end
|
504
|
+
end
|
505
|
+
|
506
|
+
# Parse JSON based options including funding_source, items, shipping_options, address and shipping_address
|
507
|
+
[:funding_sources, :shipping_options, :items, :shipping_address, :address].each do |sym|
|
508
|
+
begin
|
509
|
+
options[sym] = JSON.parse options[sym] unless options[sym].nil?
|
510
|
+
rescue => e
|
511
|
+
logger.warn("Unexpected exception while parsing JSON option #{sym}: #{e.message}\n#{e.backtrace.join("\n")}")
|
512
|
+
options[sym] = nil
|
513
|
+
end
|
514
|
+
end
|
515
|
+
|
516
|
+
# Filter the options that has second level options including funding_source, items, shipping_options, address and shipping_address
|
517
|
+
[:shipping_address, :address].each do |key|
|
518
|
+
options[key] = filter_hash_options options[key], [:name, :address1, :address2, :city, :state, :country, :phone, :zip] unless options[key].nil?
|
519
|
+
end
|
520
|
+
options[:funding_sources] = filter_hash_options options[:funding_sources], [:source] unless options[:funding_sources].nil?
|
521
|
+
options[:shipping_options] = filter_array_options options[:shipping_options], [:default, :amount, :name], [:amount], currency unless options[:shipping_options].nil?
|
522
|
+
options[:items] = filter_array_options options[:items], [:name, :number, :quantity, :amount, :description, :url, :category], [:amount], currency unless options[:items].nil?
|
523
|
+
end
|
524
|
+
|
525
|
+
def filter_array_options(option, allowed_keys, amount_keys = [], currency = nil)
|
526
|
+
return nil if option.nil? || !option.is_a?(Array)
|
527
|
+
sub_options = []
|
528
|
+
option.each do |item|
|
529
|
+
next unless item.is_a?(Hash)
|
530
|
+
sub_hash = filter_hash_options item, allowed_keys, amount_keys, currency
|
531
|
+
sub_options << sub_hash unless sub_hash.nil?
|
532
|
+
end
|
533
|
+
sub_options.empty? ? nil : sub_options
|
534
|
+
end
|
535
|
+
|
536
|
+
def filter_hash_options(option, allowed_keys, amount_keys = [], currency = nil)
|
537
|
+
return nil if option.nil? || !option.is_a?(Hash)
|
538
|
+
# Because option is parsed from JSON, we need to convert to symbol keys to be used in ::Killbill::Plugin::ActiveMerchant::Utils.normalized
|
539
|
+
option.symbolize_keys!
|
540
|
+
sub_hash = {}
|
541
|
+
allowed_keys.each do |key|
|
542
|
+
sub_hash[key] = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(option, key)
|
543
|
+
sub_hash[key] = to_cents((sub_hash[key] || '0').to_f, currency) if amount_keys.include?(key) && !sub_hash[key].nil?
|
544
|
+
end
|
545
|
+
sub_hash.empty? ? nil : sub_hash
|
546
|
+
end
|
452
547
|
end
|
453
548
|
end
|
454
549
|
end
|
data/pom.xml
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
<groupId>org.kill-bill.billing.plugin.ruby</groupId>
|
27
27
|
<artifactId>paypal-express-plugin</artifactId>
|
28
28
|
<packaging>pom</packaging>
|
29
|
-
<version>4.1.
|
29
|
+
<version>4.1.5</version>
|
30
30
|
<name>paypal-express-plugin</name>
|
31
31
|
<url>http://github.com/killbill/killbill-paypal-express-plugin</url>
|
32
32
|
<description>Plugin for accessing Paypal Express Checkout as a payment gateway</description>
|
@@ -41,4 +41,93 @@ describe Killbill::PaypalExpress::PaymentPlugin do
|
|
41
41
|
notification = ''
|
42
42
|
gw_notification = @plugin.process_notification notification, properties, context
|
43
43
|
end
|
44
|
+
|
45
|
+
it 'should correctly add and filter optional parameters' do
|
46
|
+
# Basic option test
|
47
|
+
options = { :amount => 9900,
|
48
|
+
:some_property => true}
|
49
|
+
amount = 99.99
|
50
|
+
amount_in_cents = 9999
|
51
|
+
property_hash = { :noShipping => true,
|
52
|
+
:max_amount => amount
|
53
|
+
}
|
54
|
+
@plugin.send(:add_optional_parameters, options, property_hash, 'USD')
|
55
|
+
expected_options = { :amount => 9900,
|
56
|
+
:some_property => true,
|
57
|
+
:no_shipping => true,
|
58
|
+
:max_amount => amount_in_cents
|
59
|
+
}
|
60
|
+
options.should == expected_options
|
61
|
+
|
62
|
+
# Test with correct option format and unwanted property, e.g., fakeKey and unlimited
|
63
|
+
options = { :amount => 9900,
|
64
|
+
:some_property => true}
|
65
|
+
amount = 99.99
|
66
|
+
amount_in_cents = 9999
|
67
|
+
property_hash = { :noShipping => true,
|
68
|
+
:max_amount => amount,
|
69
|
+
:subtotal => amount,
|
70
|
+
:shipping => amount,
|
71
|
+
:handling => amount,
|
72
|
+
:tax => amount,
|
73
|
+
:fakeKey => 'unlimited',
|
74
|
+
:insuranceTotal => amount,
|
75
|
+
:shipping_discount => amount,
|
76
|
+
:shipping_options => [{:default => false, :name => 'jack', :amount => amount, :unlimited => true}].to_json,
|
77
|
+
:items => [{:name => 'john', :number => 111, :quantity => 12, :amount => amount, :description => 'jacket', :url => 'test', :category => 'unknown', :unlimited => true}].to_json,
|
78
|
+
:shipping_address => {:name => 'john', :address1 => '111', :address2 => '12', :city => 'palo alto', :state => 'ca', :country => 'jacket', :phone => 'test', :zip => 'unknown', :family => 'unknown'}.to_json,
|
79
|
+
:address => {:name => 'john', :address1 => '111', :address2 => '12', :city => 'palo alto', :state => 'ca', :country => 'jacket', :phone => 'test', :zip => 'unknown', :family => 'unknown'}.to_json,
|
80
|
+
:funding_sources => {:source => 'unknown'}.to_json
|
81
|
+
}
|
82
|
+
@plugin.send(:add_optional_parameters, options, property_hash, 'USD')
|
83
|
+
expected_options = { :amount => 9900,
|
84
|
+
:some_property => true,
|
85
|
+
:no_shipping => true,
|
86
|
+
:max_amount => amount_in_cents,
|
87
|
+
:subtotal => amount_in_cents,
|
88
|
+
:shipping => amount_in_cents,
|
89
|
+
:handling => amount_in_cents,
|
90
|
+
:tax => amount_in_cents,
|
91
|
+
:insurance_total => amount_in_cents,
|
92
|
+
:shipping_discount => amount_in_cents,
|
93
|
+
:shipping_options => [{:default => false, :name => 'jack', :amount => amount_in_cents}],
|
94
|
+
:items => [{:name => 'john', :number => 111, :quantity => 12, :amount => amount_in_cents, :description => 'jacket', :url => 'test', :category => 'unknown'}],
|
95
|
+
:shipping_address => {:name => 'john', :address1 => '111', :address2 => '12', :state => 'ca', :city => 'palo alto', :country => 'jacket', :phone => 'test', :zip => 'unknown'},
|
96
|
+
:address => {:name => 'john', :address1 => '111', :address2 => '12', :state => 'ca', :city => 'palo alto', :country => 'jacket', :phone => 'test', :zip => 'unknown'},
|
97
|
+
:funding_sources => {:source => 'unknown'}
|
98
|
+
}
|
99
|
+
options.should == expected_options
|
100
|
+
|
101
|
+
# Test with incorrect option format and invalid json format
|
102
|
+
options = {}
|
103
|
+
property_hash = { :no_shipping => true,
|
104
|
+
:max_amount => amount,
|
105
|
+
:subtotal => amount,
|
106
|
+
:shipping => amount,
|
107
|
+
:handling => amount,
|
108
|
+
:tax => amount,
|
109
|
+
:fakeKey => 'unlimited',
|
110
|
+
:insurance_total => amount,
|
111
|
+
:shipping_discount => amount,
|
112
|
+
:shipping_options => "{\"default\":\"false\", [name]:\"jack\", \"amount\":12}",
|
113
|
+
:items => {:name => 'john', :number => 111, :quantity => 12, :amount => amount, :description => 'jacket', :url => 'test', :category => 'unknown', :unlimited => true}.to_json,
|
114
|
+
:shipping_address => [{:name => 'john', :address1 => '111', :address2 => '12', :city => 'amount', :country => 'jacket', :phone => 'test', :zip => 'unknown'}].to_json,
|
115
|
+
:address => [{:name => 'john', :address1 => '111', :address2 => '12', :city => 'amount', :country => 'jacket', :phone => 'test', :zip => 'unknown'}].to_json
|
116
|
+
}
|
117
|
+
@plugin.send(:add_optional_parameters, options, property_hash, 'USD')
|
118
|
+
expected_options = { :no_shipping => true,
|
119
|
+
:max_amount => amount_in_cents,
|
120
|
+
:subtotal => amount_in_cents,
|
121
|
+
:shipping => amount_in_cents,
|
122
|
+
:handling => amount_in_cents,
|
123
|
+
:tax => amount_in_cents,
|
124
|
+
:insurance_total => amount_in_cents,
|
125
|
+
:shipping_discount => amount_in_cents,
|
126
|
+
:items => nil,
|
127
|
+
:shipping_options => nil,
|
128
|
+
:shipping_address => nil,
|
129
|
+
:address => nil
|
130
|
+
}
|
131
|
+
options.should == expected_options
|
132
|
+
end
|
44
133
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: killbill-paypal-express
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1.
|
4
|
+
version: 4.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kill Bill core team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: killbill
|