Class: ActiveMerchant::Billing::WompiGateway

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

Constant Summary

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 = {}) ⇒ WompiGateway

Returns a new instance of WompiGateway.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/active_merchant/billing/gateways/wompi.rb', line 16

def initialize(options = {})
  ## Sandbox keys have prefix pub_test_ and prv_test_
  ## Production keys have prefix pub_prod_ and prv_prod_
  begin
    requires!(options, :prod_private_key, :prod_public_key)
  rescue ArgumentError
    begin
      requires!(options, :test_private_key, :test_public_key)
    rescue ArgumentError
      raise ArgumentError, 'Gateway requires both test_private_key and test_public_key, or both prod_private_key and prod_public_key'
    end
  end
  super
end

Instance Method Details

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



42
43
44
45
46
47
48
49
50
51
# File 'lib/active_merchant/billing/gateways/wompi.rb', line 42

def authorize(money, payment, options = {})
  post = {
    public_key: public_key,
    type: 'CARD',
    financial_operation: 'PREAUTHORIZATION'
  }
  add_auth_params(post, money, payment, options)

  commit('authorize', post, '/payment_sources_sync')
end

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



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

def capture(money, authorization, options = {})
  post = {
    reference: options[:reference] || generate_reference,
    public_key: public_key,
    payment_source_id: authorization.to_i
  }
  add_invoice(post, money, options)
  commit('capture', post, '/transactions_sync')
end

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



31
32
33
34
35
36
37
38
39
40
# File 'lib/active_merchant/billing/gateways/wompi.rb', line 31

def purchase(money, payment, options = {})
  post = {
    reference: options[:reference] || generate_reference,
    public_key: public_key
  }
  add_invoice(post, money, options)
  add_card(post, payment, options)

  commit('sale', post, '/transactions_sync')
end

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



63
64
65
66
67
68
69
# File 'lib/active_merchant/billing/gateways/wompi.rb', line 63

def refund(money, authorization, options = {})
  # post = { amount_in_cents: amount(money).to_i, transaction_id: authorization.to_s }
  # commit('refund', post, '/refunds_sync')

  # All refunds will instead be voided. This is temporary.
  void(authorization, options, money)
end

#scrub(transcript) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/active_merchant/billing/gateways/wompi.rb', line 80

def scrub(transcript)
  transcript.gsub(/(Bearer )\w+/, '\1[REDACTED]').
    gsub(/(\\\"number\\\":\\\")\d+/, '\1[REDACTED]').
    gsub(/(\\\"cvc\\\":\\\")\d+/, '\1[REDACTED]').
    gsub(/(\\\"phone_number\\\":\\\")\+?\d+/, '\1[REDACTED]').
    gsub(/(\\\"email\\\":\\\")\S+\\\",/, '\1[REDACTED]\",').
    gsub(/(\\\"legal_id\\\":\\\")\d+/, '\1[REDACTED]')
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/active_merchant/billing/gateways/wompi.rb', line 76

def supports_scrubbing?
  true
end

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



71
72
73
74
# File 'lib/active_merchant/billing/gateways/wompi.rb', line 71

def void(authorization, options = {}, money = nil)
  post = money ? { amount_in_cents: amount(money).to_i } : {}
  commit('void', post, "/transactions/#{authorization}/void_sync")
end