Class: ActiveMerchant::Billing::PaypalStandardGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/paypal_standard.rb

Constant Summary collapse

ENDPOINTS =
{
  generate_token: '/v1/oauth2/token',
  create_order: '/v2/checkout/orders',
  capture_order: '/v2/checkout/orders/%{id}/capture',
  refund: '/v2/payments/captures/%{id}/refund'
}
SOFT_DECLINE_CODES =
%w[INVALID_REQUEST AUTHENTICATION_FAILURE UNPROCESSABLE_ENTITY RATE_LIMIT_REACHED].freeze
SUCCESS_CODES =
%w[COMPLETED].freeze

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#add_field_to_post_if_present, #add_fields_to_post_if_present, #card_brand, card_brand, #generate_unique_id, inherited, #scrub, #supported_countries, supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #supports_scrubbing?, #test?

Methods included from CreditCardFormatting

#expdate, #format

Methods included from PostsData

included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request

Constructor Details

#initialize(options = {}) ⇒ PaypalStandardGateway

Returns a new instance of PaypalStandardGateway.



22
23
24
25
26
27
28
29
30
31
# File 'lib/active_merchant/billing/gateways/paypal_standard.rb', line 22

def initialize(options = {})
  requires!(options, :client_id, :client_secret)
  @client_id = options[:client_id]
  @client_secret = options[:client_secret]
  @response_http_code = nil

  super
  @access_token = setup_access_token
  @request_id = SecureRandom.uuid
end

Instance Method Details

#capture(authorization, options = {}) ⇒ Object



45
46
47
48
49
# File 'lib/active_merchant/billing/gateways/paypal_standard.rb', line 45

def capture(authorization, options = {})
  post = {}

  commit(:capture_order, post, authorization)
end

#purchase(amount, payment_method, options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/active_merchant/billing/gateways/paypal_standard.rb', line 33

def purchase(amount, payment_method, options = {})
  post ||= {}

  amount = to_currency(amount)

  add_payment_intent(post)
  add_purchase_units(post, amount, options)
  add_payment_source(post, payment_method, options)

  commit(:create_order, post)
end

#refund(amount, authorization, options = {}) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/active_merchant/billing/gateways/paypal_standard.rb', line 51

def refund(amount, authorization, options = {})
  post = {}

  amount = to_currency(amount)

  add_refund_amount(post, amount, options)
  add_refund_reason(post, options)

  commit(:refund, post, authorization)
end