solidus_paypal_commerce_platform 0.4.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +23 -4
  3. data/.github/stale.yml +1 -17
  4. data/.rubocop.yml +2 -1
  5. data/CHANGELOG.md +194 -147
  6. data/Gemfile +14 -1
  7. data/README.md +2 -2
  8. data/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/button_actions.js +7 -4
  9. data/app/controllers/solidus_paypal_commerce_platform/orders_controller.rb +3 -2
  10. data/app/controllers/solidus_paypal_commerce_platform/paypal_orders_controller.rb +1 -1
  11. data/app/models/solidus_paypal_commerce_platform/gateway.rb +0 -2
  12. data/app/models/solidus_paypal_commerce_platform/payment_method.rb +7 -6
  13. data/app/models/solidus_paypal_commerce_platform/payment_source.rb +1 -1
  14. data/app/models/solidus_paypal_commerce_platform/paypal_address.rb +6 -2
  15. data/app/models/solidus_paypal_commerce_platform/paypal_order.rb +26 -34
  16. data/bin/sandbox +3 -24
  17. data/lib/generators/solidus_paypal_commerce_platform/install/install_generator.rb +46 -21
  18. data/lib/paypal/access_token.rb +22 -0
  19. data/lib/paypal/lib.rb +19 -0
  20. data/lib/paypal/paypal_checkout_sdk/orders/orders_authorize_request.rb +42 -0
  21. data/lib/paypal/paypal_checkout_sdk/orders/orders_capture_request.rb +40 -0
  22. data/lib/paypal/paypal_checkout_sdk/orders/orders_create_request.rb +34 -0
  23. data/lib/paypal/paypal_checkout_sdk/orders/orders_get_request.rb +24 -0
  24. data/lib/paypal/paypal_checkout_sdk/orders/orders_patch_request.rb +25 -0
  25. data/lib/paypal/paypal_checkout_sdk/orders/orders_validate_request.rb +32 -0
  26. data/lib/paypal/paypal_checkout_sdk/payments/authorizations_capture_request.rb +36 -0
  27. data/lib/paypal/paypal_checkout_sdk/payments/authorizations_get_request.rb +24 -0
  28. data/lib/paypal/paypal_checkout_sdk/payments/authorizations_reauthorize_request.rb +43 -0
  29. data/lib/paypal/paypal_checkout_sdk/payments/authorizations_void_request.rb +25 -0
  30. data/lib/paypal/paypal_checkout_sdk/payments/captures_get_request.rb +24 -0
  31. data/lib/paypal/paypal_checkout_sdk/payments/captures_refund_request.rb +38 -0
  32. data/lib/paypal/paypal_checkout_sdk/payments/refunds_get_request.rb +24 -0
  33. data/lib/paypal/paypal_environment.rb +39 -0
  34. data/lib/paypal/paypal_http_client.rb +56 -0
  35. data/lib/paypal/token_requests.rb +42 -0
  36. data/lib/solidus_paypal_commerce_platform/access_token_authorization_request.rb +1 -1
  37. data/lib/solidus_paypal_commerce_platform/client.rb +7 -4
  38. data/lib/solidus_paypal_commerce_platform/configuration.rb +1 -1
  39. data/lib/solidus_paypal_commerce_platform/paypal_checkout_sdk/orders/orders_authorize_request.rb +48 -0
  40. data/lib/solidus_paypal_commerce_platform/paypal_checkout_sdk/orders/orders_capture_request.rb +46 -0
  41. data/lib/solidus_paypal_commerce_platform/paypal_checkout_sdk/orders/orders_patch_request.rb +27 -0
  42. data/lib/solidus_paypal_commerce_platform/paypal_checkout_sdk/orders/orders_validate_request.rb +36 -0
  43. data/lib/solidus_paypal_commerce_platform/paypal_checkout_sdk/payments/authorizations_reauthorize_request.rb +50 -0
  44. data/lib/solidus_paypal_commerce_platform/paypal_checkout_sdk/payments/captures_refund_request.rb +43 -0
  45. data/lib/solidus_paypal_commerce_platform/version.rb +1 -1
  46. data/lib/solidus_paypal_commerce_platform.rb +1 -0
  47. data/solidus_paypal_commerce_platform.gemspec +8 -7
  48. metadata +54 -28
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Solidus Paypal Commerce Platform
2
2
 
3
- [![CircleCI](https://circleci.com/gh/solidusio-contrib/solidus_paypal_commerce_platform.svg?style=shield)](https://circleci.com/gh/solidusio-contrib/solidus_paypal_commerce_platform)
4
- [![codecov](https://codecov.io/gh/solidusio-contrib/solidus_paypal_commerce_platform/branch/master/graph/badge.svg)](https://codecov.io/gh/solidusio-contrib/solidus_paypal_commerce_platform)
3
+ [![CircleCI](https://circleci.com/gh/solidusio/solidus_paypal_commerce_platform.svg?style=shield)](https://circleci.com/gh/solidusio/solidus_paypal_commerce_platform)
4
+ [![codecov](https://codecov.io/gh/solidusio/solidus_paypal_commerce_platform/branch/master/graph/badge.svg)](https://codecov.io/gh/solidusio/solidus_paypal_commerce_platform)
5
5
 
6
6
  The official PayPal integration of Solidus.
7
7
 
@@ -7,9 +7,9 @@ SolidusPaypalCommercePlatform.hideOverlay = function() {
7
7
  }
8
8
 
9
9
  SolidusPaypalCommercePlatform.handleError = function(error) {
10
- console.log(error.name, error.message)
11
- console.log("PayPal Debug ID: " + error.debug_id)
10
+ console.error(error);
12
11
  alert("There was a problem connecting with PayPal.")
12
+ throw error
13
13
  }
14
14
 
15
15
  SolidusPaypalCommercePlatform.sendOrder = function(payment_method_id) {
@@ -181,8 +181,11 @@ SolidusPaypalCommercePlatform.addPayment = function(paypal_amount, payment_metho
181
181
  })
182
182
  }
183
183
 
184
- SolidusPaypalCommercePlatform.updateAddress = function(response) {
185
- var updated_address = response.purchase_units[0].shipping.address
184
+ SolidusPaypalCommercePlatform.updateAddress = function(response) {
185
+ var shipping = response.purchase_units[0].shipping;
186
+ if (!shipping) return Promise.resolve({});
187
+
188
+ var updated_address = shipping.address;
186
189
  return Spree.ajax({
187
190
  url: '/solidus_paypal_commerce_platform/update_address',
188
191
  method: 'POST',
@@ -2,7 +2,6 @@
2
2
 
3
3
  module SolidusPaypalCommercePlatform
4
4
  class OrdersController < ::Spree::Api::BaseController
5
- before_action :load_order, except: :create
6
5
  skip_before_action :authenticate_user
7
6
  include ::Spree::Core::ControllerHelpers::Auth
8
7
 
@@ -10,7 +9,7 @@ module SolidusPaypalCommercePlatform
10
9
  authorize! :create, ::Spree::Order
11
10
 
12
11
  @order = ::Spree::Order.create!(
13
- user: try_spree_current_user,
12
+ user: current_api_user,
14
13
  store: current_store,
15
14
  currency: current_pricing_options.currency
16
15
  )
@@ -25,6 +24,7 @@ module SolidusPaypalCommercePlatform
25
24
  end
26
25
 
27
26
  def update_address
27
+ load_order
28
28
  authorize! :update, @order, order_token
29
29
  paypal_address = SolidusPaypalCommercePlatform::PaypalAddress.new(@order)
30
30
 
@@ -38,6 +38,7 @@ module SolidusPaypalCommercePlatform
38
38
  end
39
39
 
40
40
  def verify_total
41
+ load_order
41
42
  authorize! :show, @order, order_token
42
43
 
43
44
  if total_is_correct?(params[:paypal_total])
@@ -15,7 +15,7 @@ module SolidusPaypalCommercePlatform
15
15
  private
16
16
 
17
17
  def load_payment_method
18
- @payment_method = ::Spree::PaymentMethod.find(params[:payment_method_id])
18
+ @payment_method = ::Spree::PaymentMethod.find(params.require(:payment_method_id))
19
19
  end
20
20
  end
21
21
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'paypal-checkout-sdk'
4
-
5
3
  module SolidusPaypalCommercePlatform
6
4
  class Gateway
7
5
  include PayPalCheckoutSdk::Orders
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusPaypalCommercePlatform
4
- class PaymentMethod < SolidusSupport.payment_method_parent_class
4
+ class PaymentMethod < ::Spree::PaymentMethod
5
5
  include SolidusPaypalCommercePlatform::ButtonOptionsHelper
6
6
  preference :client_id, :string
7
7
  preference :client_secret, :string
@@ -74,6 +74,8 @@ module SolidusPaypalCommercePlatform
74
74
  end
75
75
 
76
76
  def javascript_sdk_url(order: nil, currency: nil)
77
+ # Ref: https://developer.paypal.com/sdk/js/configuration/
78
+
77
79
  # Both instance and class respond to checkout_steps.
78
80
  step_names = order ? order.checkout_steps : ::Spree::Order.checkout_steps.keys
79
81
 
@@ -84,17 +86,16 @@ module SolidusPaypalCommercePlatform
84
86
  intent: auto_capture ? "capture" : "authorize",
85
87
  commit: commit_immediately ? "false" : "true",
86
88
  components: options[:display_credit_messaging] ? "buttons,messages" : "buttons",
87
- currency: currency
89
+ currency: currency,
88
90
  }
89
91
 
90
- parameters[:shipping_preference] = 'NO_SHIPPING' if step_names.exclude? 'delivery'
91
92
  parameters['enable-funding'] = 'venmo' if venmo_standalone_enabled?
92
93
 
93
- if !Rails.env.production? && options[:force_buyer_country].present?
94
- parameters['buyer-country'] = options[:force_buyer_country]
94
+ unless Rails.env.production?
95
+ parameters['buyer-country'] = options[:force_buyer_country].presence
95
96
  end
96
97
 
97
- "https://www.paypal.com/sdk/js?#{parameters.to_query}"
98
+ "https://www.paypal.com/sdk/js?#{parameters.compact.to_query}".html_safe # rubocop:disable Rails/OutputSafety
98
99
  end
99
100
  end
100
101
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusPaypalCommercePlatform
4
- class PaymentSource < SolidusSupport.payment_source_parent_class
4
+ class PaymentSource < ::Spree::PaymentSource
5
5
  self.table_name = "paypal_commerce_platform_sources"
6
6
  enum paypal_funding_source: {
7
7
  applepay: 0, bancontact: 1, blik: 2, boleto: 3, card: 4, credit: 5, eps: 6, giropay: 7, ideal: 8,
@@ -61,12 +61,16 @@ module SolidusPaypalCommercePlatform
61
61
 
62
62
  def address_attributes(address, recipient)
63
63
  country = ::Spree::Country.find_by(iso: address[:country_code])
64
+ state = find_state(
65
+ address[:admin_area_1] || address[:admin_area_2] || address[:state],
66
+ country,
67
+ )
64
68
 
65
69
  attributes = {
66
70
  address1: address[:address_line_1],
67
71
  address2: address[:address_line_2],
68
- state: find_state(address[:admin_area_1] || address[:state], country),
69
- state_name: address[:admin_area_1] || address[:state],
72
+ state_id: state.try(:id),
73
+ state_name: state.try(:name),
70
74
  city: address[:admin_area_2] || address[:city],
71
75
  country: country,
72
76
  zipcode: address[:postal_code],
@@ -10,14 +10,15 @@ module SolidusPaypalCommercePlatform
10
10
  {
11
11
  intent: intent,
12
12
  purchase_units: purchase_units,
13
- payer: (payer if @order.bill_address)
13
+ payer: (payer if @order.bill_address),
14
+ application_context: application_context
14
15
  }
15
16
  end
16
17
 
17
18
  def to_replace_json
18
19
  {
19
20
  op: 'replace',
20
- path: '/purchase_units/@reference_id==\'default\'',
21
+ path: "/purchase_units/@reference_id=='default'",
21
22
  value: purchase_units(include_shipping_address: false)[0]
22
23
  }
23
24
  end
@@ -44,28 +45,21 @@ module SolidusPaypalCommercePlatform
44
45
  end
45
46
 
46
47
  def name(address)
47
- if greater_than_2_10?
48
- name = ::Spree::Address::Name.new @order.ship_address.name
48
+ name = ::Spree::Address::Name.new address.name
49
49
 
50
- {
51
- given_name: name.first_name,
52
- surname: name.last_name
53
- }
54
- else
55
- {
56
- given_name: address.firstname,
57
- surname: address.lastname
58
- }
59
- end
50
+ {
51
+ given_name: name.first_name,
52
+ surname: name.last_name
53
+ }
60
54
  end
61
55
 
62
56
  def purchase_units(include_shipping_address: true)
63
57
  [
64
58
  {
65
- amount: amount,
59
+ amount: price(@order.total).merge(breakdown: breakdown),
66
60
  items: line_items,
67
61
  shipping: (shipping_info if @order.ship_address && include_shipping_address)
68
- }
62
+ }.compact
69
63
  ]
70
64
  end
71
65
 
@@ -80,31 +74,19 @@ module SolidusPaypalCommercePlatform
80
74
  end
81
75
 
82
76
  def full_name
83
- if greater_than_2_10?
84
- @order.ship_address.name
85
- else
86
- @order.ship_address.full_name
87
- end
77
+ @order.ship_address.name
88
78
  end
89
79
 
90
80
  def line_items
91
81
  @order.line_items.map{ |line_item|
92
82
  {
93
- name: line_item.product.name,
83
+ name: line_item.product.name.truncate(127),
94
84
  unit_amount: price(line_item.price),
95
- quantity: line_item.quantity
85
+ quantity: line_item.quantity.to_i.to_s
96
86
  }
97
87
  }
98
88
  end
99
89
 
100
- def amount
101
- {
102
- currency_code: @order.currency,
103
- value: @order.total,
104
- breakdown: breakdown
105
- }
106
- end
107
-
108
90
  def breakdown
109
91
  {
110
92
  item_total: price(@order.item_total),
@@ -117,12 +99,22 @@ module SolidusPaypalCommercePlatform
117
99
  def price(amount)
118
100
  {
119
101
  currency_code: @order.currency,
120
- value: amount
102
+ value: ('%.2f' % amount.to_f)
121
103
  }
122
104
  end
123
105
 
124
- def greater_than_2_10?
125
- ::Spree.solidus_gem_version >= Gem::Version.new('2.11')
106
+ def application_context
107
+ {
108
+ shipping_preference: require_shipping? ? 'SET_PROVIDED_ADDRESS' : 'NO_SHIPPING'
109
+ }
110
+ end
111
+
112
+ def require_shipping?
113
+ step_names.include? :delivery
114
+ end
115
+
116
+ def step_names
117
+ @order ? @order.checkout_steps.map(&:to_sym) : ::Spree::Order.checkout_steps.keys
126
118
  end
127
119
  end
128
120
  end
data/bin/sandbox CHANGED
@@ -49,34 +49,13 @@ fi
49
49
 
50
50
  cd ./sandbox
51
51
  cat <<RUBY >> Gemfile
52
- gem 'solidus', github: 'solidusio/solidus', branch: '$BRANCH'
53
- gem 'solidus_auth_devise', '>= 2.1.0'
54
- gem 'rails-i18n'
55
- gem 'solidus_i18n'
56
-
57
- gem '$extension_name', path: '..'
58
-
59
- group :test, :development do
60
- platforms :mri do
61
- gem 'pry-byebug'
62
- end
63
- end
52
+ gem 'solidus', github: 'solidusio/solidus', branch: '$BRANCH'
53
+ gem 'pry-byebug', platforms: :mri, groups: [:test, :development]
64
54
  RUBY
65
55
 
66
56
  unbundled bundle install --gemfile Gemfile
67
-
68
57
  unbundled bundle exec rake db:drop db:create
69
-
70
- unbundled bundle exec rails generate solidus:install \
71
- --auto-accept \
72
- --user_class=Spree::User \
73
- --enforce_available_locales=true \
74
- --with-authentication=false \
75
- --payment-method=none \
76
- $@
77
-
78
- unbundled bundle exec rails generate solidus:auth:install
79
- unbundled bundle exec rails generate ${extension_name}:install
58
+ unbundled bundle exec rails generate solidus:install --auto-accept $@
80
59
 
81
60
  echo
82
61
  echo "🚀 Sandbox app successfully created for $extension_name!"
@@ -4,44 +4,69 @@ module SolidusPaypalCommercePlatform
4
4
  module Generators
5
5
  class InstallGenerator < Rails::Generators::Base
6
6
  class_option :auto_run_migrations, type: :boolean, default: false
7
- class_option :skip_migrations, type: :boolean, default: false
7
+
8
+ # This should only be used by the solidus installer prior to v3.3.
9
+ class_option :skip_migrations, type: :boolean, default: false, hide: true
8
10
 
9
11
  source_root File.expand_path('templates', __dir__)
10
12
 
11
- def copy_initializer
13
+ def install_solidus_core_support
12
14
  template 'initializer.rb', 'config/initializers/solidus_paypal_commerce_platform.rb'
15
+ rake 'railties:install:migrations FROM=solidus_paypal_commerce_platform'
16
+ route "mount SolidusPaypalCommercePlatform::Engine, at: '/solidus_paypal_commerce_platform'"
13
17
  end
14
18
 
15
- def add_javascripts
16
- append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_paypal_commerce_platform\n" # rubocop:disable Layout/LineLength
17
- append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_paypal_commerce_platform\n" # rubocop:disable Layout/LineLength
19
+ def install_solidus_backend_support
20
+ support_code_for('solidus_backend') do
21
+ append_file(
22
+ 'vendor/assets/javascripts/spree/backend/all.js',
23
+ "//= require spree/backend/solidus_paypal_commerce_platform\n"
24
+ )
25
+ inject_into_file(
26
+ 'vendor/assets/stylesheets/spree/backend/all.css',
27
+ " *= require spree/backend/solidus_paypal_commerce_platform\n",
28
+ before: %r{\*/},
29
+ verbose: true,
30
+ )
31
+ end
18
32
  end
19
33
 
20
- def add_stylesheets
21
- inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_paypal_commerce_platform\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
22
- inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_paypal_commerce_platform\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
34
+ def install_solidus_frontend_support
35
+ support_code_for('solidus_frontend') do
36
+ append_file(
37
+ 'vendor/assets/javascripts/spree/frontend/all.js',
38
+ "//= require spree/frontend/solidus_paypal_commerce_platform\n",
39
+ )
40
+ inject_into_file(
41
+ 'vendor/assets/stylesheets/spree/frontend/all.css',
42
+ " *= require spree/frontend/solidus_paypal_commerce_platform\n",
43
+ before: %r{\*/},
44
+ verbose: true,
45
+ )
46
+ directory engine.root.join("lib/views/frontend"), 'app/views/'
47
+ end
23
48
  end
24
49
 
25
- def add_migrations
26
- run 'bin/rails railties:install:migrations FROM=solidus_paypal_commerce_platform'
27
- end
50
+ def run_migrations
51
+ return rake 'db:migrate' if options[:auto_run_migrations] && !options[:skip_migrations]
28
52
 
29
- def mount_engine
30
- insert_into_file File.join('config', 'routes.rb'), after: "Rails.application.routes.draw do\n" do
31
- "mount SolidusPaypalCommercePlatform::Engine, at: '/solidus_paypal_commerce_platform'\n"
32
- end
53
+ say_status :skip, 'db:migrate'
33
54
  end
34
55
 
35
- def run_migrations
36
- return if options[:skip_migrations]
56
+ private
37
57
 
38
- run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength
39
- if run_migrations
40
- run 'bin/rails db:migrate'
58
+ def support_code_for(gem_name, run_if: Bundler.locked_gems.specs.map(&:name).include?(gem_name), &block)
59
+ if run_if
60
+ say_status :install, "[#{engine.engine_name}] #{gem_name} code", :blue
61
+ shell.indent(&block)
41
62
  else
42
- puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
63
+ say_status :skip, "[#{engine.engine_name}] #{gem_name} code", :blue
43
64
  end
44
65
  end
66
+
67
+ def engine
68
+ SolidusPaypalCommercePlatform::Engine
69
+ end
45
70
  end
46
71
  end
47
72
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: false
2
+
3
+ module PayPal
4
+ class AccessToken
5
+ attr_accessor :access_token, :token_type, :expires_in, :date_created
6
+
7
+ def initialize(options)
8
+ @access_token = options.access_token
9
+ @token_type = options.token_type
10
+ @expires_in = options.expires_in
11
+ @date_created = Time.zone.now
12
+ end
13
+
14
+ def expired?
15
+ Time.zone.now > @date_created + @expires_in
16
+ end
17
+
18
+ def authorization_string
19
+ "#{@token_type} #{@access_token}"
20
+ end
21
+ end
22
+ end
data/lib/paypal/lib.rb ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: false
2
+
3
+ require 'paypal/paypal_environment'
4
+ require 'paypal/paypal_http_client'
5
+ require 'paypal/token_requests'
6
+ require 'paypal/access_token'
7
+ require 'paypal/paypal_checkout_sdk/orders/orders_authorize_request'
8
+ require 'paypal/paypal_checkout_sdk/orders/orders_capture_request'
9
+ require 'paypal/paypal_checkout_sdk/orders/orders_create_request'
10
+ require 'paypal/paypal_checkout_sdk/orders/orders_get_request'
11
+ require 'paypal/paypal_checkout_sdk/orders/orders_patch_request'
12
+ require 'paypal/paypal_checkout_sdk/orders/orders_validate_request'
13
+ require 'paypal/paypal_checkout_sdk/payments/authorizations_capture_request'
14
+ require 'paypal/paypal_checkout_sdk/payments/authorizations_get_request'
15
+ require 'paypal/paypal_checkout_sdk/payments/authorizations_reauthorize_request'
16
+ require 'paypal/paypal_checkout_sdk/payments/authorizations_void_request'
17
+ require 'paypal/paypal_checkout_sdk/payments/captures_get_request'
18
+ require 'paypal/paypal_checkout_sdk/payments/refunds_get_request'
19
+ require 'paypal/paypal_checkout_sdk/payments/captures_refund_request'
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: false
2
+
3
+ require 'cgi'
4
+
5
+ module PayPalCheckoutSdk
6
+ module Orders
7
+ #
8
+ # Authorizes payment for an order. The response shows details
9
+ # of authorizations. You can make this call only if you specified
10
+ # `intent=AUTHORIZE` in the create order call.
11
+ #
12
+ class OrdersAuthorizeRequest
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}/authorize?"
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 pay_pal_request_id(pay_pal_request_id)
30
+ @headers["PayPal-Request-Id"] = pay_pal_request_id
31
+ end
32
+
33
+ def prefer(prefer)
34
+ @headers["Prefer"] = prefer
35
+ end
36
+
37
+ def request_body(order_action_request)
38
+ @body = order_action_request
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: false
2
+
3
+ require 'cgi'
4
+
5
+ module PayPalCheckoutSdk
6
+ module Orders
7
+ #
8
+ # Captures a payment for an order.
9
+ #
10
+ class OrdersCaptureRequest
11
+ attr_accessor :path, :body, :headers, :verb
12
+
13
+ def initialize(order_id)
14
+ @headers = {}
15
+ @body = nil
16
+ @verb = "POST"
17
+ @path = "/v2/checkout/orders/{order_id}/capture?"
18
+
19
+ @path = @path.gsub("{order_id}", CGI.escape(order_id.to_s))
20
+ @headers["Content-Type"] = "application/json"
21
+ end
22
+
23
+ def pay_pal_client_metadata_id(pay_pal_client_metadata_id)
24
+ @headers["PayPal-Client-Metadata-Id"] = pay_pal_client_metadata_id
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(order_action_request)
36
+ @body = order_action_request
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: false
2
+
3
+ require 'cgi'
4
+
5
+ module PayPalCheckoutSdk
6
+ module Orders
7
+ #
8
+ # Creates an order. Supports only orders with one purchase unit.
9
+ #
10
+ class OrdersCreateRequest
11
+ attr_accessor :path, :body, :headers, :verb
12
+
13
+ def initialize
14
+ @headers = {}
15
+ @body = nil
16
+ @verb = "POST"
17
+ @path = "/v2/checkout/orders?"
18
+ @headers["Content-Type"] = "application/json"
19
+ end
20
+
21
+ def pay_pal_partner_attribution_id(pay_pal_partner_attribution_id)
22
+ @headers["PayPal-Partner-Attribution-Id"] = pay_pal_partner_attribution_id
23
+ end
24
+
25
+ def prefer(prefer)
26
+ @headers["Prefer"] = prefer
27
+ end
28
+
29
+ def request_body(order)
30
+ @body = order
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: false
2
+
3
+ require 'cgi'
4
+
5
+ module PayPalCheckoutSdk
6
+ module Orders
7
+ #
8
+ # Shows details for an order, by ID.
9
+ #
10
+ class OrdersGetRequest
11
+ attr_accessor :path, :body, :headers, :verb
12
+
13
+ def initialize(order_id)
14
+ @headers = {}
15
+ @body = nil
16
+ @verb = "GET"
17
+ @path = "/v2/checkout/orders/{order_id}?"
18
+
19
+ @path = @path.gsub("{order_id}", CGI.escape(order_id.to_s))
20
+ @headers["Content-Type"] = "application/json"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: false
2
+
3
+ require 'cgi'
4
+
5
+ module PayPalCheckoutSdk
6
+ module Orders
7
+ class OrdersPatchRequest
8
+ attr_accessor :path, :body, :headers, :verb
9
+
10
+ def initialize(order_id)
11
+ @headers = {}
12
+ @body = nil
13
+ @verb = "PATCH"
14
+ @path = "/v2/checkout/orders/{order_id}?"
15
+
16
+ @path = @path.gsub("{order_id}", CGI.escape(order_id.to_s))
17
+ @headers["Content-Type"] = "application/json"
18
+ end
19
+
20
+ def request_body(patch_request)
21
+ @body = patch_request
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: false
2
+
3
+ require 'cgi'
4
+
5
+ module PayPalCheckoutSdk
6
+ module Orders
7
+ #
8
+ # Validates a payment method and checks it for contingencies.
9
+ #
10
+ class OrdersValidateRequest
11
+ attr_accessor :path, :body, :headers, :verb
12
+
13
+ def initialize(order_id)
14
+ @headers = {}
15
+ @body = nil
16
+ @verb = "POST"
17
+ @path = "/v2/checkout/orders/{order_id}/validate-payment-method?"
18
+
19
+ @path = @path.gsub("{order_id}", CGI.escape(order_id.to_s))
20
+ @headers["Content-Type"] = "application/json"
21
+ end
22
+
23
+ def pay_pal_client_metadata_id(pay_pal_client_metadata_id)
24
+ @headers["PayPal-Client-Metadata-Id"] = pay_pal_client_metadata_id
25
+ end
26
+
27
+ def request_body(order_action_request)
28
+ @body = order_action_request
29
+ end
30
+ end
31
+ end
32
+ end