Class: ActiveMerchant::Billing::PlexoGateway

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

Constant Summary collapse

APPENDED_URLS =
%w(captures refunds cancellations verify)
AMOUNT_IN_RESPONSE =
%w(authonly /verify)
APPROVED_STATUS =
%w(approved authorized)

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, supported_countries, #supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #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 = {}) ⇒ PlexoGateway

Returns a new instance of PlexoGateway.


18
19
20
21
22
# File 'lib/active_merchant/billing/gateways/plexo.rb', line 18

def initialize(options = {})
  requires!(options, :client_id, :api_key)
  @credentials = options
  super
end

Instance Method Details

#authorize(money, payment, options = {}) ⇒ Object


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/active_merchant/billing/gateways/plexo.rb', line 32

def authorize(money, payment, options = {})
  post = {}
  post[:ReferenceId] = options[:reference_id] || generate_unique_id
  post[:MerchantId] = options[:merchant_id] || @credentials[:merchant_id]
  post[:Installments] = options[:installments] if options[:installments]
  post[:StatementDescriptor] = options[:statement_descriptor] if options[:statement_descriptor]
  post[:CustomerId] = options[:customer_id] if options[:customer_id]

  add_payment_method(post, payment, options)
  add_items(post, options[:items])
  (post, options[:metadata])
  add_amount(money, post, options)
  add_browser_details(post, options)
  add_capture_type(post, options)

  commit('authonly', post)
end

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


50
51
52
53
54
55
56
# File 'lib/active_merchant/billing/gateways/plexo.rb', line 50

def capture(money, authorization, options = {})
  post = {}
  post[:ReferenceId] = options[:reference_id] || generate_unique_id
  post[:Amount] = amount(money)

  commit("/#{authorization}/captures", post)
end

#purchase(money, payment, options = {}) ⇒ Object


24
25
26
27
28
29
30
# File 'lib/active_merchant/billing/gateways/plexo.rb', line 24

def purchase(money, payment, options = {})
  response = MultiResponse.run do |r|
    r.process { authorize(money, payment, options) }
    r.process { capture(money, r.authorization, options) }
  end
  response.responses.last
end

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


58
59
60
61
62
63
64
65
66
67
# File 'lib/active_merchant/billing/gateways/plexo.rb', line 58

def refund(money, authorization, options = {})
  post = {}
  post[:ReferenceId] = options[:reference_id] || generate_unique_id
  post[:Type] = options[:type] || 'refund'
  post[:Description] = options[:description]
  post[:Reason] = options[:reason]
  post[:Amount] = amount(money)

  commit("/#{authorization}/refunds", post)
end

#scrub(transcript) ⇒ Object


98
99
100
101
102
103
104
105
# File 'lib/active_merchant/billing/gateways/plexo.rb', line 98

def scrub(transcript)
  transcript.
    gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
    gsub(%r(("Number\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
    gsub(%r(("Cvc\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
    gsub(%r(("InvoiceNumber\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
    gsub(%r(("MerchantId\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]')
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)

94
95
96
# File 'lib/active_merchant/billing/gateways/plexo.rb', line 94

def supports_scrubbing?
  true
end

#verify(credit_card, options = {}) ⇒ Object


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/active_merchant/billing/gateways/plexo.rb', line 78

def verify(credit_card, options = {})
  post = {}
  post[:ReferenceId] = options[:reference_id] || generate_unique_id
  post[:MerchantId] = options[:merchant_id] || @credentials[:merchant_id]
  post[:StatementDescriptor] = options[:statement_descriptor] if options[:statement_descriptor]
  post[:CustomerId] = options[:customer_id] if options[:customer_id]
  money = options[:verify_amount].to_i || 100

  add_payment_method(post, credit_card, options)
  (post, options[:metadata])
  add_amount(money, post, options)
  add_browser_details(post, options)

  commit('/verify', post)
end

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


69
70
71
72
73
74
75
76
# File 'lib/active_merchant/billing/gateways/plexo.rb', line 69

def void(authorization, options = {})
  post = {}
  post[:ReferenceId] = options[:reference_id] || generate_unique_id
  post[:Description] = options[:description]
  post[:Reason] = options[:reason]

  commit("/#{authorization}/cancellations", post)
end