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

#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



42
43
44
45
# File 'lib/active_merchant/billing/gateways/wompi.rb', line 42

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

#scrub(transcript) ⇒ Object



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

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)


51
52
53
# File 'lib/active_merchant/billing/gateways/wompi.rb', line 51

def supports_scrubbing?
  true
end

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



47
48
49
# File 'lib/active_merchant/billing/gateways/wompi.rb', line 47

def void(authorization, options = {})
  commit('void', {}, "/transactions/#{authorization}/void")
end