Skip to content

Commit

Permalink
Merge pull request #161 from cpfergus1/nebulab/import-paypal-sdk
Browse files Browse the repository at this point in the history
Fix master, import paypal-checkout-sdk
  • Loading branch information
kennyadsl committed Sep 30, 2022
2 parents 2fe968d + 97b5c76 commit 1e3a3a4
Show file tree
Hide file tree
Showing 39 changed files with 995 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def create
authorize! :create, ::Spree::Order

@order = ::Spree::Order.create!(
user: try_spree_current_user,
user: ::Spree.solidus_gem_version >= Gem::Version.new('3.2') ? spree_current_user : try_spree_current_user,
store: current_store,
currency: current_pricing_options.currency
)
Expand Down
2 changes: 0 additions & 2 deletions app/models/solidus_paypal_commerce_platform/gateway.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'paypal-checkout-sdk'

module SolidusPaypalCommercePlatform
class Gateway
include PayPalCheckoutSdk::Orders
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module SolidusPaypalCommercePlatform
class PaymentMethod < SolidusSupport.payment_method_parent_class
class PaymentMethod < ::Spree::PaymentMethod
include SolidusPaypalCommercePlatform::ButtonOptionsHelper
preference :client_id, :string
preference :client_secret, :string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module SolidusPaypalCommercePlatform
class PaymentSource < SolidusSupport.payment_source_parent_class
class PaymentSource < ::Spree::PaymentSource
self.table_name = "paypal_commerce_platform_sources"
enum paypal_funding_source: {
applepay: 0, bancontact: 1, blik: 2, boleto: 3, card: 4, credit: 5, eps: 6, giropay: 7, ideal: 8,
Expand Down
22 changes: 22 additions & 0 deletions lib/paypal/access_token.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: false

module PayPal
class AccessToken
attr_accessor :access_token, :token_type, :expires_in, :date_created

def initialize(options)
@access_token = options.access_token
@token_type = options.token_type
@expires_in = options.expires_in
@date_created = Time.zone.now
end

def expired?
Time.zone.now > @date_created + @expires_in
end

def authorization_string
"#{@token_type} #{@access_token}"
end
end
end
19 changes: 19 additions & 0 deletions lib/paypal/lib.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: false

require 'paypal/paypal_environment'
require 'paypal/paypal_http_client'
require 'paypal/token_requests'
require 'paypal/access_token'
require 'paypal/paypal_checkout_sdk/orders/orders_authorize_request'
require 'paypal/paypal_checkout_sdk/orders/orders_capture_request'
require 'paypal/paypal_checkout_sdk/orders/orders_create_request'
require 'paypal/paypal_checkout_sdk/orders/orders_get_request'
require 'paypal/paypal_checkout_sdk/orders/orders_patch_request'
require 'paypal/paypal_checkout_sdk/orders/orders_validate_request'
require 'paypal/paypal_checkout_sdk/payments/authorizations_capture_request'
require 'paypal/paypal_checkout_sdk/payments/authorizations_get_request'
require 'paypal/paypal_checkout_sdk/payments/authorizations_reauthorize_request'
require 'paypal/paypal_checkout_sdk/payments/authorizations_void_request'
require 'paypal/paypal_checkout_sdk/payments/captures_get_request'
require 'paypal/paypal_checkout_sdk/payments/refunds_get_request'
require 'paypal/paypal_checkout_sdk/payments/captures_refund_request'
44 changes: 44 additions & 0 deletions lib/paypal/paypal_checkout_sdk/orders/orders_authorize_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: false

# 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

require 'cgi'

module PayPalCheckoutSdk
module Orders
#
# Authorizes payment for an order. The response shows details
# of authorizations. You can make this call only if you specified
# `intent=AUTHORIZE` in the create order call.
#
class OrdersAuthorizeRequest
attr_accessor :path, :body, :headers, :verb

def initialize(order_id)
@headers = {}
@body = nil
@verb = "POST"
@path = "/v2/checkout/orders/{order_id}/authorize?"

@path = @path.gsub("{order_id}", CGI.escape(order_id.to_s))
@headers["Content-Type"] = "application/json"
end

def pay_pal_client_metadata_id(pay_pal_client_metadata_id)
@headers["PayPal-Client-Metadata-Id"] = pay_pal_client_metadata_id
end

def pay_pal_request_id(pay_pal_request_id)
@headers["PayPal-Request-Id"] = pay_pal_request_id
end

def prefer(prefer)
@headers["Prefer"] = prefer
end

def request_body(order_action_request)
@body = order_action_request
end
end
end
end
42 changes: 42 additions & 0 deletions lib/paypal/paypal_checkout_sdk/orders/orders_capture_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# frozen_string_literal: false

# 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

require 'cgi'

module PayPalCheckoutSdk
module Orders
#
# Captures a payment for an order.
#
class OrdersCaptureRequest
attr_accessor :path, :body, :headers, :verb

def initialize(order_id)
@headers = {}
@body = nil
@verb = "POST"
@path = "/v2/checkout/orders/{order_id}/capture?"

@path = @path.gsub("{order_id}", CGI.escape(order_id.to_s))
@headers["Content-Type"] = "application/json"
end

def pay_pal_client_metadata_id(pay_pal_client_metadata_id)
@headers["PayPal-Client-Metadata-Id"] = pay_pal_client_metadata_id
end

def pay_pal_request_id(pay_pal_request_id)
@headers["PayPal-Request-Id"] = pay_pal_request_id
end

def prefer(prefer)
@headers["Prefer"] = prefer
end

def request_body(order_action_request)
@body = order_action_request
end
end
end
end
36 changes: 36 additions & 0 deletions lib/paypal/paypal_checkout_sdk/orders/orders_create_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: false

# 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

require 'cgi'

module PayPalCheckoutSdk
module Orders
#
# Creates an order. Supports only orders with one purchase unit.
#
class OrdersCreateRequest
attr_accessor :path, :body, :headers, :verb

def initialize
@headers = {}
@body = nil
@verb = "POST"
@path = "/v2/checkout/orders?"
@headers["Content-Type"] = "application/json"
end

def pay_pal_partner_attribution_id(pay_pal_partner_attribution_id)
@headers["PayPal-Partner-Attribution-Id"] = pay_pal_partner_attribution_id
end

def prefer(prefer)
@headers["Prefer"] = prefer
end

def request_body(order)
@body = order
end
end
end
end
26 changes: 26 additions & 0 deletions lib/paypal/paypal_checkout_sdk/orders/orders_get_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: false

# 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

require 'cgi'

module PayPalCheckoutSdk
module Orders
#
# Shows details for an order, by ID.
#
class OrdersGetRequest
attr_accessor :path, :body, :headers, :verb

def initialize(order_id)
@headers = {}
@body = nil
@verb = "GET"
@path = "/v2/checkout/orders/{order_id}?"

@path = @path.gsub("{order_id}", CGI.escape(order_id.to_s))
@headers["Content-Type"] = "application/json"
end
end
end
end
77 changes: 77 additions & 0 deletions lib/paypal/paypal_checkout_sdk/orders/orders_patch_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# frozen_string_literal: false

# 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

require 'cgi'

module PayPalCheckoutSdk
module Orders
#
# Updates an order that has the `CREATED` or `APPROVED` status. You cannot update an order with `COMPLETED` status.
# You can patch these attributes and objects:
# <table>
# <thead>
# <tr>
# <th align="left">Attribute or object</th>
# <th align="left">Operations</th>
# </tr>
# </thead>
# <tbody>
# <tr>
# <td><code>intent</code></td>
# <td align="left">Replace</td>
# </tr>
# <tr>
# <td><code>purchase_units</code></td>
# <td align="left">Replace, add</td>
# </tr>
# <tr>
# <td><code>purchase_units[].custom_id</code></td>
# <td align="left">Replace, add, remove</td>
# </tr>
# <tr>
# <td><code>purchase_units[].description</code></td>
# <td align="left">Replace, add, remove</td>
# </tr>
# <tr>
# <td><code>purchase_units[].payee.email</code></td>
# <td align="left">Replace, add</td>
# </tr>
# <tr>
# <td><code>purchase_units[].shipping</code></td>
# <td align="left">Replace, add, remove</td>
# </tr>
# <tr>
# <td><code>purchase_units[].soft_descriptor</code></td>
# <td align="left">Replace, add, remove</td>
# </tr>
# <tr>
# <td><code>purchase_units[].amount</code></td>
# <td align="left">Replace</td>
# </tr>
# <tr>
# <td><code>purchase_units[].invoice_id</code></td>
# <td align="left">Replace, add, remove</td>
# </tr>
# </tbody>
# </table>
#
class OrdersPatchRequest
attr_accessor :path, :body, :headers, :verb

def initialize(order_id)
@headers = {}
@body = nil
@verb = "PATCH"
@path = "/v2/checkout/orders/{order_id}?"

@path = @path.gsub("{order_id}", CGI.escape(order_id.to_s))
@headers["Content-Type"] = "application/json"
end

def request_body(patch_request)
@body = patch_request
end
end
end
end
34 changes: 34 additions & 0 deletions lib/paypal/paypal_checkout_sdk/orders/orders_validate_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: false

# 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

require 'cgi'

module PayPalCheckoutSdk
module Orders
#
# Validates a payment method and checks it for contingencies.
#
class OrdersValidateRequest
attr_accessor :path, :body, :headers, :verb

def initialize(order_id)
@headers = {}
@body = nil
@verb = "POST"
@path = "/v2/checkout/orders/{order_id}/validate-payment-method?"

@path = @path.gsub("{order_id}", CGI.escape(order_id.to_s))
@headers["Content-Type"] = "application/json"
end

def pay_pal_client_metadata_id(pay_pal_client_metadata_id)
@headers["PayPal-Client-Metadata-Id"] = pay_pal_client_metadata_id
end

def request_body(order_action_request)
@body = order_action_request
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: false

# 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

require 'cgi'

module PayPalCheckoutSdk
module Payments
#
# Captures an authorized payment, by ID.
#
class AuthorizationsCaptureRequest
attr_accessor :path, :body, :headers, :verb

def initialize(authorization_id)
@headers = {}
@body = nil
@verb = "POST"
@path = "/v2/payments/authorizations/{authorization_id}/capture?"

@path = @path.gsub("{authorization_id}", CGI.escape(authorization_id.to_s))
@headers["Content-Type"] = "application/json"
end

def pay_pal_request_id(pay_pal_request_id)
@headers["PayPal-Request-Id"] = pay_pal_request_id
end

def prefer(prefer)
@headers["Prefer"] = prefer
end

def request_body(capture)
@body = capture
end
end
end
end
Loading

0 comments on commit 1e3a3a4

Please sign in to comment.