workarea-paypal 2.0.9 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.json +2 -1
  3. data/.gitignore +16 -11
  4. data/CHANGELOG.md +79 -0
  5. data/README.md +105 -6
  6. data/Rakefile +4 -5
  7. data/UPGRADE.md +46 -0
  8. data/app/assets/javascripts/workarea/storefront/paypal/config.js.erb +44 -0
  9. data/app/assets/javascripts/workarea/storefront/paypal/modules/paypal_buttons.js +71 -0
  10. data/app/assets/javascripts/workarea/storefront/paypal/modules/paypal_hosted_fields.js +96 -0
  11. data/app/assets/javascripts/workarea/storefront/paypal/modules/update_checkout_submit_text.js +11 -5
  12. data/app/assets/javascripts/workarea/storefront/paypal/templates/paypal_fields.jst.ejs +43 -0
  13. data/app/controllers/workarea/storefront/checkout/place_order_controller.decorator +6 -4
  14. data/app/controllers/workarea/storefront/paypal_controller.rb +32 -26
  15. data/app/helpers/workarea/storefront/paypal_helper.rb +38 -0
  16. data/app/models/workarea/payment.decorator +17 -3
  17. data/app/models/workarea/payment/authorize/paypal.rb +13 -13
  18. data/app/models/workarea/payment/capture/paypal.rb +10 -20
  19. data/app/models/workarea/payment/null_address.rb +37 -0
  20. data/app/models/workarea/payment/purchase/paypal.rb +1 -25
  21. data/app/models/workarea/payment/refund/paypal.rb +3 -6
  22. data/app/models/workarea/payment/tender/paypal.rb +14 -2
  23. data/app/services/workarea/paypal/approve_order.rb +104 -0
  24. data/app/services/workarea/paypal/create_order.rb +177 -0
  25. data/app/services/workarea/paypal/update_order.rb +44 -0
  26. data/app/views/workarea/admin/orders/tenders/_paypal.html.haml +5 -2
  27. data/app/views/workarea/api/orders/tenders/_paypal.json.jbuilder +7 -1
  28. data/app/views/workarea/storefront/carts/_paypal_checkout.html.haml +6 -1
  29. data/app/views/workarea/storefront/checkouts/_paypal_payment.html.haml +16 -5
  30. data/app/views/workarea/storefront/order_mailer/tenders/_paypal.html.haml +5 -3
  31. data/app/views/workarea/storefront/orders/tenders/_paypal.html.haml +9 -2
  32. data/app/views/workarea/storefront/paypal/_paypal_sdk.html.haml +1 -0
  33. data/app/workers/workarea/paypal/handle_webhook_event.rb +64 -0
  34. data/config/initializers/append_points.rb +17 -5
  35. data/config/initializers/fields.rb +27 -0
  36. data/config/initializers/workarea.rb +41 -5
  37. data/config/locales/en.yml +14 -4
  38. data/config/routes.rb +3 -2
  39. data/lib/tasks/workarea/create_webhooks.rake +29 -0
  40. data/lib/workarea/paypal.rb +22 -18
  41. data/lib/workarea/paypal/engine.rb +4 -0
  42. data/lib/workarea/paypal/gateway.rb +200 -0
  43. data/lib/workarea/paypal/requests/create_webhook.rb +21 -0
  44. data/lib/workarea/paypal/requests/delete_webhook.rb +17 -0
  45. data/lib/workarea/paypal/requests/generate_token.rb +21 -0
  46. data/lib/workarea/paypal/requests/list_webhooks.rb +17 -0
  47. data/lib/workarea/paypal/version.rb +1 -1
  48. data/package.json +9 -0
  49. data/test/dummy/config/initializers/workarea.rb +1 -1
  50. data/test/factories/workarea/capture_completed_webhook.json +70 -0
  51. data/test/factories/workarea/capture_denied_webhook.json +68 -0
  52. data/test/factories/workarea/paypal.rb +34 -0
  53. data/test/helpers/workarea/storefront/paypal_helper_test.rb +35 -0
  54. data/test/integration/workarea/storefront/paypal_integration_test.rb +104 -294
  55. data/test/integration/workarea/storefront/paypal_place_order_integration_test.rb +42 -0
  56. data/test/lib/workarea/paypal/gateway_test.rb +236 -0
  57. data/test/models/workarea/payment/authorize/paypal_test.rb +57 -46
  58. data/test/models/workarea/payment/capture/paypal_test.rb +9 -51
  59. data/test/models/workarea/payment/null_address_test.rb +53 -0
  60. data/test/models/workarea/payment/refund/paypal_test.rb +39 -38
  61. data/test/models/workarea/paypal_payment_test.rb +65 -0
  62. data/test/models/workarea/search/paypal_order_text_test.rb +14 -0
  63. data/test/services/workarea/paypal/approve_order_test.rb +35 -0
  64. data/test/services/workarea/paypal/create_order_test.rb +127 -0
  65. data/test/services/workarea/paypal/update_order_test.rb +73 -0
  66. data/test/support/workarea/paypal_setup.rb +49 -0
  67. data/test/system/workarea/storefront/cart_system_test.decorator +1 -1
  68. data/test/system/workarea/storefront/logged_in_checkout_system_test.decorator +1 -1
  69. data/test/vcr_cassettes/paypal_approve_order.yml +106 -0
  70. data/test/vcr_cassettes/paypal_create_order.yml +110 -0
  71. data/test/vcr_cassettes/paypal_gateway_create_order.yml +105 -0
  72. data/test/vcr_cassettes/paypal_gateway_generate_token.yml +103 -0
  73. data/test/vcr_cassettes/paypal_gateway_get_order.yml +103 -0
  74. data/test/vcr_cassettes/paypal_gateway_update_order.yml +199 -0
  75. data/test/vcr_cassettes/paypal_gateway_webhooks.yml +403 -0
  76. data/test/vcr_cassettes/paypal_update_order.yml +204 -0
  77. data/test/workers/workarea/paypal/handle_webhook_event_test.rb +60 -0
  78. data/workarea-paypal.gemspec +2 -1
  79. metadata +65 -14
  80. data/app/services/workarea/paypal/setup.rb +0 -114
  81. data/app/services/workarea/paypal/update.rb +0 -69
  82. data/app/views/workarea/storefront/checkouts/_paypal_error.html.haml +0 -6
  83. data/app/views/workarea/storefront/order_mailer/tenders/_paypal.text.haml +0 -2
  84. data/test/dummy/config/initializers/session_store.rb +0 -3
  85. data/test/integration/workarea/storefront/place_order_integration_test.decorator +0 -11
  86. data/test/models/workarea/payment/purchase/paypal_test.rb +0 -94
  87. data/test/models/workarea/payment_test.decorator +0 -34
  88. data/test/models/workarea/search/admin/order_test.decorator +0 -32
  89. data/test/services/workarea/paypal/setup_test.rb +0 -120
  90. data/test/services/workarea/paypal/update_test.rb +0 -221
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 298668e8ec2b951d889abc29f581329a15d242f44a365e1050117623b3a0c8b3
4
- data.tar.gz: 07da63a473d39b51c0176a1e6893111462e61480b6a6fdbd02cfac21986535a9
3
+ metadata.gz: d56a6bbb39e0357ffa880a99749bf18d52baa6b2dade6b95c32faf821d9abacb
4
+ data.tar.gz: df0d898d029a70f52ecc93d0a176aa032c382fb9684b85e9d1fe1fc7b30ec8a8
5
5
  SHA512:
6
- metadata.gz: 78fe19e9ef4c724f395fc0c07b77d610a4696d82550cea831bd16f227878a880467ebc1593d9601fb84c8cb6905657d4d523572c97aa19d56ffdaedb009211df
7
- data.tar.gz: d82ba2eb4fcb99766bbeb1920512432af582bfcf0fac7316ff85e8ca565104f25d8084aab586413ca77f1736abbd2cb783e89642227cd0d4b710da7e0c32834b
6
+ metadata.gz: 59924950c8cf492d04107d95a8835cb1c008246904df6f651d2b4a88280b5f40f12458943b620757557b0aeb266643b433a374c940b3d3f31bd340fe7fb44657
7
+ data.tar.gz: e4c66e7939c429a706063b346738520485a02e239cfe50aad505d49c88148a54926d180e459e8f97cb4eb63777fda85b3b385df7018fafd62e505298496028ed
@@ -30,6 +30,7 @@
30
30
  "expect": true,
31
31
  "sinon": true,
32
32
  "fixture": true,
33
- "chai": true
33
+ "chai": true,
34
+ "paypal": true
34
35
  }
35
36
  }
data/.gitignore CHANGED
@@ -1,20 +1,25 @@
1
- .byebug_history
2
1
  .bundle/
3
- Gemfile.lock
4
- .sass-cache/
5
2
  log/*.log
6
3
  pkg/
7
- spec/dummy/public/system/dragonfly
8
- spec/dummy/db/*.sqlite3
9
- spec/dummy/log/*.log
10
- spec/dummy/tmp/
11
- spec/dummy/.sass-cache
12
- test/dummy/public/system/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/db/*.sqlite3-journal
13
6
  test/dummy/log/*.log
7
+ test/dummy/node_modules/
8
+ test/dummy/yarn-error.log
9
+ test/dummy/storage/
14
10
  test/dummy/tmp/
15
11
  .DS_Store
12
+ .byebug_history
13
+ .bundle/
14
+ .sass-cache/
15
+ Gemfile.lock
16
+ pkg/
17
+ test/dummy/tmp/
18
+ test/dummy/public/
19
+ log/*.log
20
+ test/dummy/log/*.log
21
+ test/dummy/db/*.sqlite3
22
+ test/dummy/db/*.sqlite3-journal
16
23
  node_modules
17
- test/reports
18
- package.json
19
24
  yarn.lock
20
25
  .rubocop-http*
@@ -1,3 +1,82 @@
1
+ Workarea Paypal 3.0.3 (2020-05-26)
2
+ --------------------------------------------------------------------------------
3
+
4
+ * Update Paypal BN
5
+
6
+
7
+ Ben Crouse
8
+
9
+
10
+
11
+ Workarea Paypal 3.0.2 (2020-05-14)
12
+ --------------------------------------------------------------------------------
13
+
14
+ * Fix wrong protocol when using SSL
15
+
16
+ Fixes #11
17
+
18
+ Ben Crouse
19
+
20
+ * Fix field name on #refund
21
+
22
+
23
+ Alejandro Babio
24
+
25
+
26
+
27
+ Workarea Paypal 3.0.1 (2020-03-17)
28
+ --------------------------------------------------------------------------------
29
+
30
+ * Add upgrade guide
31
+
32
+ PAYPAL-6
33
+ Matt Duffy
34
+
35
+
36
+
37
+ Workarea Paypal 3.0.0 (2020-03-03)
38
+ --------------------------------------------------------------------------------
39
+
40
+ * Improve handling of failed captures
41
+
42
+ PAYPAL-5
43
+ Matt Duffy
44
+
45
+ * Clean up NullAddress display, add partner id to all PayPal requests
46
+
47
+ PAYPAL-5
48
+ Matt Duffy
49
+
50
+ * Update README
51
+
52
+ PAYPAL-4
53
+ Matt Duffy
54
+
55
+ * Update PayPal integration for PayPal Commerce Platform API
56
+
57
+ PAYPAL-3
58
+ Matt Duffy
59
+
60
+
61
+
62
+ Workarea Paypal 2.0.9 (2019-10-30)
63
+ --------------------------------------------------------------------------------
64
+
65
+ * Fix Integration Test Failure When PO Box Config Changes
66
+
67
+ When `config.allow_shipping_address_po_box` is set to `true`, an
68
+ integration test in the PayPal plugin failed due to the shipping step
69
+ raising an error since no shipping option is available for the address.
70
+ To ensure the test is configured correctly, it's now wrapped in a
71
+ `Workarea.with_config` block, with `config.allow_shipping_address_po_box`
72
+ set to `false`. This allows the test to ensure that the proper redirect
73
+ occurs when a shipping address coming back from PayPal is invalid.
74
+
75
+ PAYPAL-83
76
+ Tom Scott
77
+
78
+
79
+
1
80
  Workarea Paypal 2.0.8 (2019-08-21)
2
81
  --------------------------------------------------------------------------------
3
82
 
data/README.md CHANGED
@@ -3,6 +3,13 @@ Workarea PayPal
3
3
 
4
4
  A Workarea Commerce plugin that adds support for PayPal payments. This plugin adds a new tender type in checkout, which allows users to pay for their items with PayPal.
5
5
 
6
+ As of v3.0, this plugin utilizes the [PayPal Commerce Platform](https://www.paypal.com/us/webapps/mpp/commerce-platform). By default this integrates PayPal's [Smart Payment Buttons](https://developer.paypal.com/docs/commerce-platform/payment/checkout/) into your Workarea Application to allow customers to use any payment method supported in their area to complete checkout on your storefront.
7
+
8
+ Upgrading to v3.0.0
9
+ --------------------------------------------------------------------------------
10
+
11
+ See the [upgrade guide](UPGRADE.md) for information on upgrading from v2.x of this plugin.
12
+
6
13
  Getting Started
7
14
  --------------------------------------------------------------------------------
8
15
 
@@ -21,21 +28,113 @@ cd path/to/application
21
28
  bundle
22
29
  ```
23
30
 
24
- Then, configure your secrets.
31
+ Then, add your client ID and secret to Workarea. See "Account Setup" below for more details.
32
+
33
+ For production environments, we recommend you run the webhooks rake task to register critical callbacks from PayPal to help keep the state of your orders on Workarea inline with the state of the PayPal transaction. See the `default_webhook_events` description under "Configuration Options" for more information.
34
+
35
+ ```bash
36
+ bin/rails workarea:paypal:create_webhooks
37
+ ```
38
+
39
+ Account Setup
40
+ --------------------------------------------------------------------------------
41
+
42
+ To begin using PayPal on your site, you will need to have a PayPal merchant account. For development, you can create an account on [developer.paypal.com](htttps://developer.paypal.com). From there you can create a sandbox REST API app, and use those credentials for any non-live environments.
43
+
44
+ Once you have a REST API application in your PayPal sandbox, you must add the client ID and secret to your Workarea application. This can be done through admin configuration, environment variables, Rails credentials, or hard-coded Workarea configuration.
45
+
46
+ ### Admin configuration
47
+
48
+ The PayPal plugin adds admin configuration fields to allow admin user's to set credentials without the need for developer intervention. Log in as an admin user, navigate to the Configuration page, find the PayPal section and add the client ID and secret.
49
+
50
+ ### Environment Variables
51
+
52
+ If the storing and setting of credentials needs to be more dynamic, you can utilize environment variables. Set the environment variables below to connect to PayPal.
53
+
54
+ `WORKAREA_PAYPAL_CLIENT_ID`
55
+ `WORKAREA_PAYPAL_CLIENT_SECRET`
56
+
57
+ ### Rails Credentials
58
+
59
+ This option can be used for any environment, but is most useful in development to store the sandbox credentials within the codebase securely, allowing anyone with the `master.key` of your application to have PayPal configured when they load their application in development.
60
+
61
+ To add your PayPal info to your Rails credentials, open your credentials file for editing:
62
+
63
+ ```bash
64
+ EDITOR=vi bin/rails credentials:edit
65
+ ```
66
+
67
+ Then, add a PayPal section:
25
68
 
26
69
  ```yaml
27
70
  paypal:
28
- login:
29
- password:
30
- signature:
71
+ client_id: YOUR_CLIENT_ID
72
+ client_secret: YOUR_CLIENT_SECRET
73
+ ```
74
+
75
+ ### Hard-coded configuration
76
+
77
+ This option is not ideal, as it will prevent admin configuration from ever being used, but can be necessary if you need to automate the switching of PayPal accounts in a multi-site environment. It is **strongly** recommended that you store the credentials elsewhere and load them into your configuration dynamically if you need to use this option.
78
+
79
+ In your `config/initializers/workarea.rb`, add:
80
+
81
+ ```ruby
82
+ Workarea.configure do |config|
83
+ config.paypal_client_id = 'YOUR_CLIENT_ID'
84
+ config.paypal_client_secret = 'YOUR_CLIENT_SECRET'
85
+ end
31
86
  ```
32
87
 
33
- These credentials will be sent to you by your client, who should have a PayPal merchant account set up already. If not, or you wish to develop locally, [sign up for a sandbox account](https://developer.paypal.com/developer/accounts/).
88
+ Configuration Options
89
+ --------------------------------------------------------------------------------
90
+
91
+ `config.paypal_environment`
92
+
93
+ The [PayPal Checkout SDK](https://github.com/paypal/Checkout-Ruby-SDK) gem uses different environment classes depending on whether you are interacting with sandbox or live environments. This config by default will point to the sandbox environment unless you are in production. If you need to customize which environment you wish to connect to you'll have to modify the value of this config. Accepted values are `'Paypal::LiveEnvironment'` or
94
+ `'PayPal::SandboxEnvironment'`.
95
+
96
+ `config.paypal_sdk_params`
97
+
98
+ This config holds a hash of values to be passed as query string arguments to the PayPal when fetching the javascript SDK. See the [PayPal documentation](https://developer.paypal.com/docs/checkout/reference/customize-sdk/) for options. By default, the plugin will pass the client_id, and `'commit' => false`. It will add `'debug' => true` if you are in development for easier troubleshooting.
99
+
100
+ `config.default_webhook_events`
101
+
102
+ PayPal offers a number of [webhook integration options](https://developer.paypal.com/docs/integration/direct/webhooks/rest-webhooks/) that will make calls to your application when something happens within PayPal. You can [create webhooks manually](https://developer.paypal.com/docs/integration/direct/webhooks/rest-webhooks/#to-use-the-dashboard-to-subscribe-to-events) within the PayPal dashboard, but Workarea provides a more automated way to subscribe to events through the `workarea:paypal:create_webhooks` rake task. When run, this rake task will clear any existing webhooks and create a webhook for each event in `config.default_webhook_events`. By default, `PAYMENT.CAPTURE.COMPLETED` and `PAYMENT.CAPTURE.DENIED` are the only events supported by the plugin. If you wish to add more supported events you will also have to provide logic within [`Workarea::Paypal::HandleWebhookEvent`](https://github.com/workarea-commerce/workarea-paypal/blob/master/app/workers/workarea/paypal/handle_webhook_event.rb) to update your application appropriately.
103
+
104
+
105
+ `config.use_paypal_hosted_fields`
106
+
107
+ This configuration toggles on [PayPal Custom Card Fields](https://developer.paypal.com/docs/limited-release/custom-card-fields/) which allows you to use PayPal as your primary credit card payment processor. See "Hosted Fields" below for more information.
108
+
109
+ ### Javascript Configuration
34
110
 
35
- ## International Addresses
111
+ Both Smart Payment Buttons and Hosted Fields provide configuration within the javascript `WORKAREA.config` object to customize options passed when initializing those behaviors.
112
+
113
+ `WORKAREA.config.paypalButtons`
114
+
115
+ Customize the Smart Payment Buttons options. See the [PayPal documentation](https://developer.paypal.com/docs/checkout/integration-features/customize-button/) for options.
116
+
117
+ `WORKAREA.config.paypalHostedFields`
118
+
119
+ Customize the Hosted Fields options. See the [PayPal documentation](https://developer.paypal.com/docs/limited-release/custom-card-fields/reference) for options.
120
+
121
+ Hosted Fields
122
+ --------------------------------------------------------------------------------
123
+
124
+ The PayPal Commerce Platform allows you to add unbranded, custom credit card fields to your checkout to accept payments directly on your site. When enabled via `config.use_paypal_hosted_fields`, the Workarea plugin integrates this directly into the existing checkout payment step by replacing the default credit card fields with fields rendered by PayPal. This enables you to accept credit card payments with no other payment processor except PayPal.
125
+
126
+ This does require providing additional information to PayPal through a Workarea-specific partner signup. For sandbox accounts, You can [complete this process](https://www.sandbox.paypal.com/bizsignup/partner/entry?channelId=partner&channel=marketplace&product=ppcp&partnerId=M3XMHZJKTFK88&integrationType=FO) without additional communication using your **sandbox business account login** (found in the PayPal developer dashboard under Sandbox > Accounts). For live environments, contact [Workarea](https://www.workarea.com/pages/contact-us) or reach out to PayPal for more information how you can enable this behavior for your site.
127
+
128
+ Additional Information
129
+ --------------------------------------------------------------------------------
130
+
131
+ See the [PayPal Documentation](https://developer.paypal.com/docs/commerce-platform/) for more information on the PayPal Commerce Platform.
132
+
133
+ ### International Addresses
36
134
 
37
135
  When working with international addresses, the data from PayPal regarding country and region codes is not guaranteed to match the identifiers used in Workarea (derived from our usage of the [countries](https://github.com/hexorx/countries) gem), because the 2-digit codes identifying countries and regions are not the same. Therefore, you may have some issues when accepting international payments through PayPal, and thus some changes will need to be applied to ensure a seamless checkout process for international PayPal users.
38
136
 
137
+
39
138
  Workarea Commerce Documentation
40
139
  --------------------------------------------------------------------------------
41
140
 
data/Rakefile CHANGED
@@ -39,13 +39,12 @@ desc "Release version #{Workarea::Paypal::VERSION} of the gem"
39
39
  task :release do
40
40
  host = "https://#{ENV['BUNDLE_GEMS__WEBLINC__COM']}@gems.weblinc.com"
41
41
 
42
- #Rake::Task['workarea:changelog'].execute
43
- #system 'git add CHANGELOG.md'
44
- #system 'git commit -m "Update CHANGELOG"'
45
- #system 'git push origin HEAD'
42
+ Rake::Task['workarea:changelog'].execute
43
+ system 'git add CHANGELOG.md'
44
+ system 'git commit -m "Update CHANGELOG"'
46
45
 
47
46
  system "git tag -a v#{Workarea::Paypal::VERSION} -m 'Tagging #{Workarea::Paypal::VERSION}'"
48
- system 'git push --tags'
47
+ system 'git push origin HEAD --follow-tags'
49
48
 
50
49
  system 'gem build workarea-paypal.gemspec'
51
50
  system "gem push workarea-paypal-#{Workarea::Paypal::VERSION}.gem"
@@ -0,0 +1,46 @@
1
+ Upgrading This Gem from v2.x to v3.0.0
2
+ ================================================================================
3
+
4
+ As of this gem's v3.0 version, this plugin utilizes the [PayPal Commerce Platform](https://www.paypal.com/us/webapps/mpp/commerce-platform). By default this integrates PayPal's [Smart Payment Buttons](https://developer.paypal.com/docs/commerce-platform/payment/checkout/) into your Workarea Application to allow customers to use any payment method supported in their area to complete checkout on your storefront.
5
+
6
+ Upgrading will require approximately the following steps:
7
+
8
+ 1. New PayPal Account Setup (see [README](https://github.com/workarea-commerce/workarea-paypal#account-setup))
9
+ * Create a new [PayPal business account](https://www.paypal.com/signin/client?flow=provisionUser) to generate sandbox credentials.
10
+ * Add credentials to your application.
11
+
12
+
13
+ 2. Update your application Gemfile
14
+
15
+ `gem 'workarea-paypal', '~> 3.0.0'`
16
+
17
+ 3. Rework any customizations your application made around PayPal. Information around what change is provided below to give you an idea of areas you might need to address.
18
+
19
+ 4. Test locally and/or staging to ensure your application is communicating with PayPal.
20
+
21
+ 5. Generate a live REST API app within PayPal to get production credentials.
22
+
23
+ 6. Add production credentials and deploy.
24
+
25
+ Plugin Changes
26
+ ---------------
27
+
28
+ This represents a completely new integration that will require any customizations your application has made to PayPal behavior to be updated to be compatible with v3 of this plugin. As with any change, you should follow the setup steps for the plugin and test extensively to ensure everything is working properly before deploying to production.
29
+
30
+ This upgrade will require a new PayPal merchant account and updating credentials for both your sandbox and live environments. Contact Workarea Support or PayPal directly with any questions regarding transitioning your application.
31
+
32
+ ### Storefront Changes
33
+
34
+ Previous versions of this plugin rendered a static PayPal button on the top and bottom of the cart page, and provided a text-based payment option on the payment step of checkout.
35
+
36
+ The PayPal Commerce Platform integration is more dynamic. The cart page and the step both render a single instance of the [Smart Payment Buttons](https://developer.paypal.com/docs/commerce-platform/payment/checkout/). This generates a dynamic set of PayPal payment options that can vary based on device, customer location, and more. You will need to take this change into consideration and update your views to accommodate the visual change.
37
+
38
+ These buttons are rendered within an iframe controlled by PayPal. This iframe can change height for certain payment options, so its container should be flexible to account for that potential behavior. There is set of configuration options you can pass to the `paypal.Buttons` javascript method to customize how these buttons are rendered. Workarea provides a javascript configuration object, `WORKAREA.config.paypalButtons` to modify options passed. See the [PayPal documentation](https://developer.paypal.com/docs/checkout/integration-features/customize-button/) for valid options.
39
+
40
+ Smart Payment Buttons are entirely javascript-based. Part of this behavior eliminates a full redirect away from your site to PayPal, in favor of a separate window that allows the customer to interact with PayPal, and the PayPal javascript SDK to communicate back to your application without leaving the page.
41
+
42
+ ### Payment Processing Changes
43
+
44
+ Previously, this plugin relied on the ActiveMerchant PayPal implementation to process payments with PayPal. As of v3, this is no longer the case, and instead utilizes PayPal's own [Checkout Ruby SDK](https://github.com/paypal/Checkout-Ruby-SDK). This provides the environment and client logic to securely communicate with PayPal.
45
+
46
+ With this new gateway, PayPal payments are captured immediately at the time a customer places an order. This is a change from the authorization behavior of the old API that allowed for captures at a later time. You will want to make sure your OMS and other payment related behaviors work with this change. If you need to continue doing authorizations when an order is placed, contact PayPal or Workarea Support to discuss options. As of this writing, the PayPal Commerce Platform has some features that do not yet support authorizations.
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @namespace WORKAREA
3
+ */
4
+
5
+ (function () {
6
+ 'use strict';
7
+
8
+ /**
9
+ * @namespace WORKAREA.config
10
+ * @property {object} paypalButtons
11
+ * See https://developer.paypal.com/docs/checkout/integration-features/customize-button/
12
+ * for information on configuration options.
13
+ */
14
+ WORKAREA.config.paypalButtons = {
15
+ style: {
16
+ color: 'blue',
17
+ tagline: false,
18
+ }
19
+ };
20
+
21
+ /**
22
+ * @namespace WORKAREA.config
23
+ * @property {object} paypalHostedFields
24
+ * See https://developer.paypal.com/docs/limited-release/custom-card-fields/reference
25
+ * for information on configuration options.
26
+ */
27
+ WORKAREA.config.paypalHostedFields = {
28
+ fields: {
29
+ number: {
30
+ selector: '#paypal-credit-card-number',
31
+ placeholder: 'Credit Card Number',
32
+ },
33
+ cvv: {
34
+ selector: '#paypal-cvv-field',
35
+ placeholder: 'CVV',
36
+ },
37
+ expirationDate: {
38
+ selector: '#paypal-expiration-field',
39
+ placeholder: 'MM/YYYY',
40
+ }
41
+ }
42
+ };
43
+
44
+ })();
@@ -0,0 +1,71 @@
1
+ /**
2
+ * @namespace WORKAREA.paypalButtons
3
+ */
4
+ WORKAREA.registerModule('paypalButtons', (function () {
5
+ 'use strict';
6
+
7
+ var requestWrapper = function (requestData) {
8
+ var deferred = $.Deferred();
9
+
10
+ $.ajax(requestData)
11
+ .done(function(data) {
12
+ deferred.resolve(data);
13
+ })
14
+ .fail(function(data, status, xhr) {
15
+ deferred.reject(xhr);
16
+ });
17
+
18
+ return deferred.promise();
19
+ },
20
+
21
+ createOrder = function() {
22
+ return requestWrapper({
23
+ url: WORKAREA.routes.storefront.paypalPath(),
24
+ type: 'post',
25
+ dataType: 'json'
26
+ }).then(function (data) {
27
+ return data.id;
28
+ });
29
+ },
30
+
31
+ onApprove = function(data) {
32
+ return requestWrapper({
33
+ url: WORKAREA.routes.storefront.paypalApprovedPath({ id: data.orderID }),
34
+ type: 'put',
35
+ dataType: 'json'
36
+ }).then(function(data) {
37
+ window.location = data.redirect_url; }
38
+ );
39
+ },
40
+
41
+ getConfig = function () {
42
+ return _.assign({}, WORKAREA.config.paypalButtons, {
43
+ createOrder: createOrder,
44
+ onApprove: onApprove
45
+ });
46
+ },
47
+
48
+ setup = function($container) {
49
+ paypal
50
+ .Buttons(getConfig())
51
+ .render($container[0]);
52
+ },
53
+
54
+ /**
55
+ * @method
56
+ * @name init
57
+ * @memberof WORKAREA.paypalButtons
58
+ */
59
+ init = function ($scope) {
60
+ var $buttonContainer = $('#paypal-button-container', $scope);
61
+
62
+ if (window.paypal === undefined) { return; }
63
+ if (_.isEmpty($buttonContainer)) { return; }
64
+
65
+ setup($buttonContainer);
66
+ };
67
+
68
+ return {
69
+ init: init
70
+ };
71
+ }()));