solidus_paypal_commerce_platform 0.3.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +25 -2
  3. data/.rubocop.yml +6 -5
  4. data/CHANGELOG.md +180 -122
  5. data/Gemfile +16 -3
  6. data/README.md +27 -2
  7. data/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/button_actions.js +3 -1
  8. data/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/buttons.js +14 -0
  9. data/app/controllers/solidus_paypal_commerce_platform/orders_controller.rb +1 -1
  10. data/app/controllers/solidus_paypal_commerce_platform/payments_controller.rb +4 -2
  11. data/app/helpers/solidus_paypal_commerce_platform/button_options_helper.rb +4 -0
  12. data/app/models/solidus_paypal_commerce_platform/gateway.rb +20 -3
  13. data/app/models/solidus_paypal_commerce_platform/payment_method.rb +21 -1
  14. data/app/models/solidus_paypal_commerce_platform/payment_source.rb +12 -1
  15. data/app/models/solidus_paypal_commerce_platform/paypal_order.rb +6 -21
  16. data/app/models/solidus_paypal_commerce_platform/wizard.rb +1 -1
  17. data/bin/rails-engine +1 -1
  18. data/config/locales/en.yml +34 -1
  19. data/db/migrate/20211220133406_add_paypal_funding_source_to_paypal_commerce_platform_sources.rb +5 -0
  20. data/lib/paypal/access_token.rb +22 -0
  21. data/lib/paypal/lib.rb +19 -0
  22. data/lib/paypal/paypal_checkout_sdk/orders/orders_authorize_request.rb +44 -0
  23. data/lib/paypal/paypal_checkout_sdk/orders/orders_capture_request.rb +42 -0
  24. data/lib/paypal/paypal_checkout_sdk/orders/orders_create_request.rb +36 -0
  25. data/lib/paypal/paypal_checkout_sdk/orders/orders_get_request.rb +26 -0
  26. data/lib/paypal/paypal_checkout_sdk/orders/orders_patch_request.rb +77 -0
  27. data/lib/paypal/paypal_checkout_sdk/orders/orders_validate_request.rb +34 -0
  28. data/lib/paypal/paypal_checkout_sdk/payments/authorizations_capture_request.rb +38 -0
  29. data/lib/paypal/paypal_checkout_sdk/payments/authorizations_get_request.rb +26 -0
  30. data/lib/paypal/paypal_checkout_sdk/payments/authorizations_reauthorize_request.rb +45 -0
  31. data/lib/paypal/paypal_checkout_sdk/payments/authorizations_void_request.rb +27 -0
  32. data/lib/paypal/paypal_checkout_sdk/payments/captures_get_request.rb +26 -0
  33. data/lib/paypal/paypal_checkout_sdk/payments/captures_refund_request.rb +40 -0
  34. data/lib/paypal/paypal_checkout_sdk/payments/refunds_get_request.rb +26 -0
  35. data/lib/paypal/paypal_environment.rb +39 -0
  36. data/lib/paypal/paypal_http_client.rb +56 -0
  37. data/lib/paypal/token_requests.rb +42 -0
  38. data/lib/solidus_paypal_commerce_platform/access_token_authorization_request.rb +1 -1
  39. data/lib/solidus_paypal_commerce_platform/client.rb +4 -4
  40. data/lib/solidus_paypal_commerce_platform/configuration.rb +4 -4
  41. data/lib/solidus_paypal_commerce_platform/engine.rb +11 -3
  42. data/lib/solidus_paypal_commerce_platform/paypal_checkout_sdk/orders/orders_authorize_request.rb +48 -0
  43. data/lib/solidus_paypal_commerce_platform/paypal_checkout_sdk/orders/orders_capture_request.rb +46 -0
  44. data/lib/solidus_paypal_commerce_platform/paypal_checkout_sdk/orders/orders_patch_request.rb +80 -0
  45. data/lib/solidus_paypal_commerce_platform/paypal_checkout_sdk/orders/orders_validate_request.rb +36 -0
  46. data/lib/solidus_paypal_commerce_platform/paypal_checkout_sdk/payments/authorizations_reauthorize_request.rb +50 -0
  47. data/lib/solidus_paypal_commerce_platform/paypal_checkout_sdk/payments/captures_refund_request.rb +43 -0
  48. data/lib/solidus_paypal_commerce_platform/testing_support/factories.rb +2 -1
  49. data/lib/solidus_paypal_commerce_platform/version.rb +1 -1
  50. data/lib/solidus_paypal_commerce_platform.rb +1 -0
  51. data/lib/views/backend/spree/admin/payments/source_views/_paypal_commerce_platform.html.erb +3 -0
  52. data/lib/views/frontend/solidus_paypal_commerce_platform/payments/_payment.html.erb +4 -0
  53. data/lib/views/frontend/spree/checkout/payment/_paypal_commerce_platform.html.erb +17 -3
  54. data/solidus_paypal_commerce_platform.gemspec +9 -8
  55. metadata +52 -78
  56. data/spec/features/backend/new_payment_method_spec.rb +0 -40
  57. data/spec/features/frontend/cart_spec.rb +0 -46
  58. data/spec/features/frontend/checkout_spec.rb +0 -89
  59. data/spec/features/frontend/product_spec.rb +0 -91
  60. data/spec/jobs/solidus_paypal_commerce_platform/fixtures/CHECKOUT.ORDER.COMPLETED.v2.json +0 -121
  61. data/spec/jobs/solidus_paypal_commerce_platform/fixtures/CHECKOUT.ORDER.PROCESSED.v2.json +0 -121
  62. data/spec/jobs/solidus_paypal_commerce_platform/fixtures/PAYMENT.CAPTURE.COMPLETED.v1.json +0 -50
  63. data/spec/jobs/solidus_paypal_commerce_platform/fixtures/PAYMENT.CAPTURE.COMPLETED.v2.json +0 -72
  64. data/spec/jobs/solidus_paypal_commerce_platform/fixtures/PAYMENT.CAPTURE.DENIED.v1.json +0 -50
  65. data/spec/jobs/solidus_paypal_commerce_platform/fixtures/PAYMENT.CAPTURE.DENIED.v2.json +0 -68
  66. data/spec/jobs/solidus_paypal_commerce_platform/fixtures/PAYMENT.CAPTURE.REFUNDED.v1.json +0 -51
  67. data/spec/jobs/solidus_paypal_commerce_platform/fixtures/PAYMENT.CAPTURE.REFUNDED.v2.json +0 -63
  68. data/spec/jobs/solidus_paypal_commerce_platform/webhook_job_spec.rb +0 -44
  69. data/spec/lib/solidus_paypal_commerce_platform/client_spec.rb +0 -21
  70. data/spec/lib/solidus_paypal_commerce_platform/configuration_spec.rb +0 -91
  71. data/spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb +0 -129
  72. data/spec/models/solidus_paypal_commerce_platform/payment_source_spec.rb +0 -62
  73. data/spec/models/solidus_paypal_commerce_platform/paypal_address_spec.rb +0 -67
  74. data/spec/models/solidus_paypal_commerce_platform/paypal_order_spec.rb +0 -33
  75. data/spec/models/solidus_paypal_commerce_platform/state_guesser_spec.rb +0 -38
  76. data/spec/models/solidus_paypal_commerce_platform/wizard_spec.rb +0 -9
  77. data/spec/requests/solidus_paypal_commerce_platform/orders_controller_spec.rb +0 -36
  78. data/spec/requests/solidus_paypal_commerce_platform/shipping_rates_controller_spec.rb +0 -44
  79. data/spec/requests/solidus_paypal_commerce_platform/wizard_controller_spec.rb +0 -44
  80. data/spec/spec_helper.rb +0 -32
  81. data/spec/support/capybara.rb +0 -11
  82. data/spec/support/paypal_sdk_script_tag_helper.rb +0 -13
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: false
2
+
3
+ # This class was generated on Mon, 27 Aug 2018 13:51:59 PDT by version 0.1.0-dev+904328-dirty of Braintree SDK Generator
4
+
5
+ require 'cgi'
6
+
7
+ module PayPalCheckoutSdk
8
+ module Orders
9
+ #
10
+ # Validates a payment method and checks it for contingencies.
11
+ #
12
+ class OrdersValidateRequest
13
+ attr_accessor :path, :body, :headers, :verb
14
+
15
+ def initialize(order_id)
16
+ @headers = {}
17
+ @body = nil
18
+ @verb = "POST"
19
+ @path = "/v2/checkout/orders/{order_id}/validate-payment-method?"
20
+
21
+ @path = @path.gsub("{order_id}", CGI.escape(order_id.to_s))
22
+ @headers["Content-Type"] = "application/json"
23
+ end
24
+
25
+ def pay_pal_client_metadata_id(pay_pal_client_metadata_id)
26
+ @headers["PayPal-Client-Metadata-Id"] = pay_pal_client_metadata_id
27
+ end
28
+
29
+ def request_body(order_action_request)
30
+ @body = order_action_request
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: false
2
+
3
+ # This class was generated on Mon, 27 Aug 2018 13:52:18 PDT by version 0.1.0-dev+904328-dirty of Braintree SDK Generator
4
+
5
+ require 'cgi'
6
+
7
+ module PayPalCheckoutSdk
8
+ module Payments
9
+ #
10
+ # Captures an authorized payment, by ID.
11
+ #
12
+ class AuthorizationsCaptureRequest
13
+ attr_accessor :path, :body, :headers, :verb
14
+
15
+ def initialize(authorization_id)
16
+ @headers = {}
17
+ @body = nil
18
+ @verb = "POST"
19
+ @path = "/v2/payments/authorizations/{authorization_id}/capture?"
20
+
21
+ @path = @path.gsub("{authorization_id}", CGI.escape(authorization_id.to_s))
22
+ @headers["Content-Type"] = "application/json"
23
+ end
24
+
25
+ def pay_pal_request_id(pay_pal_request_id)
26
+ @headers["PayPal-Request-Id"] = pay_pal_request_id
27
+ end
28
+
29
+ def prefer(prefer)
30
+ @headers["Prefer"] = prefer
31
+ end
32
+
33
+ def request_body(capture)
34
+ @body = capture
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: false
2
+
3
+ # This class was generated on Mon, 27 Aug 2018 13:52:18 PDT by version 0.1.0-dev+904328-dirty of Braintree SDK Generator
4
+
5
+ require 'cgi'
6
+
7
+ module PayPalCheckoutSdk
8
+ module Payments
9
+ #
10
+ # Shows details for an authorized payment, by ID.
11
+ #
12
+ class AuthorizationsGetRequest
13
+ attr_accessor :path, :body, :headers, :verb
14
+
15
+ def initialize(authorization_id)
16
+ @headers = {}
17
+ @body = nil
18
+ @verb = "GET"
19
+ @path = "/v2/payments/authorizations/{authorization_id}?"
20
+
21
+ @path = @path.gsub("{authorization_id}", CGI.escape(authorization_id.to_s))
22
+ @headers["Content-Type"] = "application/json"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: false
2
+
3
+ # This class was generated on Mon, 27 Aug 2018 13:52:18 PDT by version 0.1.0-dev+904328-dirty of Braintree SDK Generator
4
+
5
+ require 'cgi'
6
+
7
+ module PayPalCheckoutSdk
8
+ module Payments
9
+ #
10
+ # Reauthorizes an authorized PayPal account payment, by ID. To ensure that funds are still available,
11
+ # reauthorize a payment after its initial three-day honor period expires. You can reauthorize a
12
+ # payment only once from days four to 29.<br/><br/> If 30 days have transpired since the date of the
13
+ # original authorization, you must create an authorized payment instead of reauthorizing the original
14
+ # authorized payment.<br/><br/>A reauthorized payment itself has a new honor period of three
15
+ # days.<br/><br/>You can reauthorize an authorized payment once for up to 115% of the original
16
+ # authorized amount, not to exceed an increase of $75 USD.<br/><br/>Supports only the `amount` request
17
+ # parameter.
18
+ #
19
+ class AuthorizationsReauthorizeRequest
20
+ attr_accessor :path, :body, :headers, :verb
21
+
22
+ def initialize(authorization_id)
23
+ @headers = {}
24
+ @body = nil
25
+ @verb = "POST"
26
+ @path = "/v2/payments/authorizations/{authorization_id}/reauthorize?"
27
+
28
+ @path = @path.gsub("{authorization_id}", CGI.escape(authorization_id.to_s))
29
+ @headers["Content-Type"] = "application/json"
30
+ end
31
+
32
+ def pay_pal_request_id(pay_pal_request_id)
33
+ @headers["PayPal-Request-Id"] = pay_pal_request_id
34
+ end
35
+
36
+ def prefer(prefer)
37
+ @headers["Prefer"] = prefer
38
+ end
39
+
40
+ def request_body(reauthorize_request)
41
+ @body = reauthorize_request
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: false
2
+
3
+ # This class was generated on Mon, 27 Aug 2018 13:52:18 PDT by version 0.1.0-dev+904328-dirty of Braintree SDK Generator
4
+
5
+ require 'cgi'
6
+
7
+ module PayPalCheckoutSdk
8
+ module Payments
9
+ #
10
+ # Voids, or cancels, an authorized payment, by ID. You cannot
11
+ # void an authorized payment that has been fully captured.
12
+ #
13
+ class AuthorizationsVoidRequest
14
+ attr_accessor :path, :body, :headers, :verb
15
+
16
+ def initialize(authorization_id)
17
+ @headers = {}
18
+ @body = nil
19
+ @verb = "POST"
20
+ @path = "/v2/payments/authorizations/{authorization_id}/void?"
21
+
22
+ @path = @path.gsub("{authorization_id}", CGI.escape(authorization_id.to_s))
23
+ @headers["Content-Type"] = "application/json"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: false
2
+
3
+ # This class was generated on Mon, 27 Aug 2018 13:52:18 PDT by version 0.1.0-dev+904328-dirty of Braintree SDK Generator
4
+
5
+ require 'cgi'
6
+
7
+ module PayPalCheckoutSdk
8
+ module Payments
9
+ #
10
+ # Shows details for a captured payment, by ID.
11
+ #
12
+ class CapturesGetRequest
13
+ attr_accessor :path, :body, :headers, :verb
14
+
15
+ def initialize(capture_id)
16
+ @headers = {}
17
+ @body = nil
18
+ @verb = "GET"
19
+ @path = "/v2/payments/captures/{capture_id}?"
20
+
21
+ @path = @path.gsub("{capture_id}", CGI.escape(capture_id.to_s))
22
+ @headers["Content-Type"] = "application/json"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: false
2
+
3
+ # This class was generated on Mon, 27 Aug 2018 13:52:18 PDT by version 0.1.0-dev+904328-dirty of Braintree SDK Generator
4
+
5
+ require 'cgi'
6
+
7
+ module PayPalCheckoutSdk
8
+ module Payments
9
+ #
10
+ # Refunds a captured payment, by ID. For a full refund, include
11
+ # an empty payload in the JSON request body. For a partial refund,
12
+ # include an <code>amount</code> object in the JSON request body.
13
+ #
14
+ class CapturesRefundRequest
15
+ attr_accessor :path, :body, :headers, :verb
16
+
17
+ def initialize(capture_id)
18
+ @headers = {}
19
+ @body = nil
20
+ @verb = "POST"
21
+ @path = "/v2/payments/captures/{capture_id}/refund?"
22
+
23
+ @path = @path.gsub("{capture_id}", CGI.escape(capture_id.to_s))
24
+ @headers["Content-Type"] = "application/json"
25
+ end
26
+
27
+ def pay_pal_request_id(pay_pal_request_id)
28
+ @headers["PayPal-Request-Id"] = pay_pal_request_id
29
+ end
30
+
31
+ def prefer(prefer)
32
+ @headers["Prefer"] = prefer
33
+ end
34
+
35
+ def request_body(refund_request)
36
+ @body = refund_request
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: false
2
+
3
+ # This class was generated on Mon, 27 Aug 2018 13:52:18 PDT by version 0.1.0-dev+904328-dirty of Braintree SDK Generator
4
+
5
+ require 'cgi'
6
+
7
+ module PayPalCheckoutSdk
8
+ module Payments
9
+ #
10
+ # Shows details for a refund, by ID.
11
+ #
12
+ class RefundsGetRequest
13
+ attr_accessor :path, :body, :headers, :verb
14
+
15
+ def initialize(refund_id)
16
+ @headers = {}
17
+ @body = nil
18
+ @verb = "GET"
19
+ @path = "/v2/payments/refunds/{refund_id}?"
20
+
21
+ @path = @path.gsub("{refund_id}", CGI.escape(refund_id.to_s))
22
+ @headers["Content-Type"] = "application/json"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: false
2
+
3
+ require 'paypalhttp'
4
+ require "base64"
5
+
6
+ module PayPal
7
+ SANDBOXAPI = 'https://api.sandbox.paypal.com'.freeze
8
+ LIVEAPI = 'https://api.paypal.com'.freeze
9
+ SANDBOXWEB = 'https://sandbox.paypal.com'.freeze
10
+ LIVEWEB = 'https://paypal.com'.freeze
11
+
12
+ class PayPalEnvironment < PayPalHttp::Environment
13
+ attr_accessor :client_id, :client_secret, :web_url
14
+
15
+ def initialize(client_id, client_secret, base_url, web_url)
16
+ super(base_url)
17
+ @client_id = client_id
18
+ @client_secret = client_secret
19
+ @web_url = web_url
20
+ end
21
+
22
+ def authorization_string
23
+ encoded = Base64.strict_encode64("#{@client_id}:#{@client_secret}")
24
+ "Basic #{encoded}"
25
+ end
26
+ end
27
+
28
+ class SandboxEnvironment < PayPal::PayPalEnvironment
29
+ def initialize(client_id, client_secret)
30
+ super(client_id, client_secret, PayPal::SANDBOXAPI, PayPal::SANDBOXWEB)
31
+ end
32
+ end
33
+
34
+ class LiveEnvironment < PayPal::PayPalEnvironment
35
+ def initialize(client_id, client_secret)
36
+ super(client_id, client_secret, PayPal::LIVEAPI, PayPal::LIVEWEB)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: false
2
+
3
+ require 'paypalhttp'
4
+ require 'openssl'
5
+
6
+ module PayPal
7
+ class PayPalHttpClient < PayPalHttp::HttpClient
8
+ attr_accessor :refresh_token
9
+
10
+ def initialize(environment, refresh_token = nil)
11
+ super(environment)
12
+ @refresh_token = refresh_token
13
+
14
+ add_injector(&:_sign_request)
15
+ add_injector(&:_add_headers)
16
+ end
17
+
18
+ def user_agent
19
+ library_details ||= "ruby #{RUBY_VERSION}p#{RUBY_PATCHLEVEL}-#{RUBY_PLATFORM}"
20
+ begin
21
+ library_details << ";#{OpenSSL::OPENSSL_LIBRARY_VERSION}"
22
+ rescue NameError
23
+ library_details << ";OpenSSL #{OpenSSL::OPENSSL_VERSION}"
24
+ end
25
+
26
+ "PayPalSDK-FORK/rest-sdk-ruby (#{library_details})"
27
+ end
28
+
29
+ def _sign_request(request)
30
+ return if !_has_auth_header(request) && !_is_auth_request(request)
31
+
32
+ if !@access_token || @access_token.expired?
33
+ access_token_request = PayPal.access_token_request.new(@environment, @refresh_token)
34
+ token_response = execute(access_token_request)
35
+ @access_token = PayPal::AccessToken.new(token_response.result)
36
+ end
37
+ request.headers["Authorization"] = @access_token.authorization_string
38
+ end
39
+
40
+ def _add_headers(request)
41
+ request.headers["Accept-Encoding"] = "gzip"
42
+ request.headers["sdk_name"] = "Checkout SDK"
43
+ request.headers["sdk_tech_stack"] = "Ruby#{RUBY_VERSION}"
44
+ request.headers["api_integration_type"] = "PAYPALSDK"
45
+ end
46
+
47
+ def _is_auth_request(request)
48
+ request.path == '/v1/oauth2/token' ||
49
+ request.path == '/v1/identity/openidconnect/tokenservice'
50
+ end
51
+
52
+ def _has_auth_header(request)
53
+ request.headers.key?("Authorization")
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: false
2
+
3
+ module PayPal
4
+ class AccessTokenRequest
5
+ attr_accessor :path, :body, :headers, :verb
6
+
7
+ def initialize(environment, refresh_token = nil)
8
+ @path = "/v1/oauth2/token"
9
+ @body = {
10
+ grant_type: "client_credentials",
11
+ }
12
+
13
+ if refresh_token
14
+ @body[:grant_type] = "refresh_token"
15
+ @body[:refresh_token] = refresh_token
16
+ end
17
+
18
+ @headers = {
19
+ "Content-Type" => "application/x-www-form-urlencoded",
20
+ "Authorization" => environment.authorization_string,
21
+ }
22
+ @verb = "POST"
23
+ end
24
+ end
25
+
26
+ class RefreshTokenRequest
27
+ attr_accessor :path, :body, :headers, :verb
28
+
29
+ def initialize(environment, authorization_code)
30
+ @path = "/v1/identity/openidconnect/tokenservice"
31
+ @body = {
32
+ grant_type: "authorization_code",
33
+ code: authorization_code,
34
+ }
35
+ @headers = {
36
+ "Content-Type" => "application/x-www-form-urlencoded",
37
+ "Authorization" => environment.authorization_string,
38
+ }
39
+ @verb = "POST"
40
+ end
41
+ end
42
+ end
@@ -9,7 +9,7 @@ module SolidusPaypalCommercePlatform
9
9
  @path = "/v1/oauth2/token"
10
10
  @headers = {
11
11
  "Content-Type" => "application/x-www-form-urlencoded",
12
- "Authorization" => environment.authorizationString,
12
+ "Authorization" => environment.authorization_string,
13
13
  }
14
14
  @body = {
15
15
  grant_type: "authorization_code",
@@ -3,7 +3,7 @@
3
3
  require 'solidus_paypal_commerce_platform/access_token_authorization_request'
4
4
  require 'solidus_paypal_commerce_platform/fetch_merchant_credentials_request'
5
5
 
6
- require 'paypal-checkout-sdk'
6
+ require 'paypalhttp'
7
7
 
8
8
  module SolidusPaypalCommercePlatform
9
9
  class Client
@@ -13,6 +13,8 @@ module SolidusPaypalCommercePlatform
13
13
  request.headers["PayPal-Partner-Attribution-Id"] = SolidusPaypalCommercePlatform.config.partner_code
14
14
  }.freeze
15
15
 
16
+ Response = Struct.new(:status_code, :error)
17
+
16
18
  attr_reader :environment
17
19
 
18
20
  def initialize(client_id:, client_secret: "", test_mode: nil)
@@ -29,7 +31,7 @@ module SolidusPaypalCommercePlatform
29
31
  @paypal_client.execute(request)
30
32
  rescue PayPalHttp::HttpError => e
31
33
  Rails.logger.error e.result
32
- OpenStruct.new(status_code: 422, error: e.result)
34
+ Response.new(status_code: 422, error: e.result)
33
35
  end
34
36
 
35
37
  def execute_with_response(request, success_message: nil, failure_message: nil)
@@ -60,8 +62,6 @@ module SolidusPaypalCommercePlatform
60
62
  )).result
61
63
  end
62
64
 
63
- private
64
-
65
65
  def wrap_response(response, success_message: nil, failure_message: nil)
66
66
  if SUCCESS_STATUS_CODES.include? response.status_code
67
67
  success_message ||= "Success."
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'paypal-checkout-sdk'
3
+ require 'paypal/paypal_environment'
4
4
 
5
5
  module SolidusPaypalCommercePlatform
6
6
  class Configuration
@@ -39,7 +39,7 @@ module SolidusPaypalCommercePlatform
39
39
  end
40
40
 
41
41
  def default_env
42
- return ENV['PAYPAL_ENV'] if ENV['PAYPAL_ENV'] # rubocop:disable Rails/EnvironmentVariableAccess
42
+ return ENV['PAYPAL_ENV'] if ENV['PAYPAL_ENV']
43
43
 
44
44
  case Rails.env
45
45
  when 'production'
@@ -60,11 +60,11 @@ module SolidusPaypalCommercePlatform
60
60
  end
61
61
 
62
62
  def partner_id
63
- @partner_id ||= ENV['PAYPAL_PARTNER_ID'] || DEFAULT_PARTNER_ID[env.to_sym] # rubocop:disable Rails/EnvironmentVariableAccess
63
+ @partner_id ||= ENV.fetch('PAYPAL_PARTNER_ID') { DEFAULT_PARTNER_ID[env.to_sym] }
64
64
  end
65
65
 
66
66
  def partner_client_id
67
- @partner_client_id ||= ENV['PAYPAL_PARTNER_CLIENT_ID'] || DEFAULT_PARTNER_CLIENT_ID[env.to_sym] # rubocop:disable Rails/EnvironmentVariableAccess
67
+ @partner_client_id ||= ENV.fetch('PAYPAL_PARTNER_CLIENT_ID') { DEFAULT_PARTNER_CLIENT_ID[env.to_sym] }
68
68
  end
69
69
 
70
70
  def partner_code
@@ -15,9 +15,17 @@ module SolidusPaypalCommercePlatform
15
15
  engine_name 'solidus_paypal_commerce_platform'
16
16
 
17
17
  initializer "solidus_paypal_commerce_platform.add_payment_method", after: "spree.register.payment_methods" do |app|
18
- app.config.spree.payment_methods << SolidusPaypalCommercePlatform::PaymentMethod
19
- SolidusPaypalCommercePlatform::PaymentMethod.allowed_admin_form_preference_types << :paypal_select
20
- Spree::PermittedAttributes.source_attributes.concat [:paypal_order_id, :authorization_id, :paypal_email]
18
+ app.config.to_prepare do
19
+ app.config.spree.payment_methods << SolidusPaypalCommercePlatform::PaymentMethod
20
+
21
+ unless SolidusPaypalCommercePlatform::PaymentMethod.allowed_admin_form_preference_types.include?(:paypal_select)
22
+ SolidusPaypalCommercePlatform::PaymentMethod.allowed_admin_form_preference_types << :paypal_select
23
+ end
24
+
25
+ old_source_attributes = ::Spree::PermittedAttributes.source_attributes
26
+ new_source_attributes = [:paypal_order_id, :authorization_id, :paypal_email, :paypal_funding_source]
27
+ ::Spree::PermittedAttributes.source_attributes.concat(new_source_attributes - old_source_attributes)
28
+ end
21
29
  end
22
30
 
23
31
  initializer "solidus_paypal_commerce_platform.add_wizard", after: "spree.register.payment_methods" do |app|
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ # frozen_string_literal :true
4
+
5
+ # This module was automatically generated from paypal_checkout_sdk 1.0.1
6
+
7
+ require 'cgi'
8
+
9
+ module SolidusPaypalCommercePlatform
10
+ module PayPalCheckoutSdk
11
+ module Orders
12
+ #
13
+ # Authorizes payment for an order. The response shows details of authorizations.
14
+ # You can make this call only if you specified `intent=AUTHORIZE` in the
15
+ # create order call.
16
+ #
17
+ class OrdersAuthorizeRequest
18
+ attr_accessor :path, :body, :headers, :verb
19
+
20
+ def initialize(order_id)
21
+ @headers = {}
22
+ @body = nil
23
+ @verb = "POST"
24
+ @path = "/v2/checkout/orders/{order_id}/authorize?"
25
+
26
+ @path = @path.gsub("{order_id}", CGI.escape(order_id.to_s))
27
+ @headers["Content-Type"] = "application/json"
28
+ end
29
+
30
+ def pay_pal_client_metadata_id(pay_pal_client_metadata_id)
31
+ @headers["PayPal-Client-Metadata-Id"] = pay_pal_client_metadata_id
32
+ end
33
+
34
+ def pay_pal_request_id(pay_pal_request_id)
35
+ @headers["PayPal-Request-Id"] = pay_pal_request_id
36
+ end
37
+
38
+ def prefer(prefer)
39
+ @headers["Prefer"] = prefer
40
+ end
41
+
42
+ def request_body(order_action_request)
43
+ @body = order_action_request
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ # frozen_string_literal :true
4
+
5
+ # This module was automatically generated from paypal_checkout_sdk 1.0.1
6
+
7
+ require 'cgi'
8
+
9
+ module SolidusPaypalCommercePlatform
10
+ module PayPalCheckoutSdk
11
+ module Orders
12
+ #
13
+ # Captures a payment for an order.
14
+ #
15
+ class OrdersCaptureRequest
16
+ attr_accessor :path, :body, :headers, :verb
17
+
18
+ def initialize(order_id)
19
+ @headers = {}
20
+ @body = nil
21
+ @verb = "POST"
22
+ @path = "/v2/checkout/orders/{order_id}/capture?"
23
+
24
+ @path = @path.gsub("{order_id}", CGI.escape(order_id.to_s))
25
+ @headers["Content-Type"] = "application/json"
26
+ end
27
+
28
+ def pay_pal_client_metadata_id(pay_pal_client_metadata_id)
29
+ @headers["PayPal-Client-Metadata-Id"] = pay_pal_client_metadata_id
30
+ end
31
+
32
+ def pay_pal_request_id(pay_pal_request_id)
33
+ @headers["PayPal-Request-Id"] = pay_pal_request_id
34
+ end
35
+
36
+ def prefer(prefer)
37
+ @headers["Prefer"] = prefer
38
+ end
39
+
40
+ def request_body(order_action_request)
41
+ @body = order_action_request
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end