Class: ActiveMerchant::Billing::VposGateway

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

Constant Summary collapse

ENDPOINTS =
{
  pci_encryption_key: '/vpos/api/0.3/application/encryption-key',
  pay_pci_buy_encrypted: '/vpos/api/0.3/pci/encrypted',
  pci_buy_rollback: '/vpos/api/0.3/pci_buy/rollback',
  refund: '/vpos/api/0.3/refunds'
}

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

Returns a new instance of VposGateway.


26
27
28
29
30
31
32
# File 'lib/active_merchant/billing/gateways/vpos.rb', line 26

def initialize(options = {})
  requires!(options, :private_key, :public_key)
  @private_key = options[:private_key]
  @public_key = options[:public_key]
  @shop_process_id = options[:shop_process_id] || SecureRandom.random_number(10**15)
  super
end

Instance Method Details

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


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/active_merchant/billing/gateways/vpos.rb', line 34

def purchase(money, payment, options = {})
  commerce = options[:commerce] || @options[:commerce]
  commerce_branch = options[:commerce_branch] || @options[:commerce_branch]

  token = generate_token(@shop_process_id, 'pay_pci', commerce, commerce_branch, amount(money), currency(money))

  post = {}
  post[:token] = token
  post[:commerce] = commerce.to_s
  post[:commerce_branch] = commerce_branch.to_s
  post[:shop_process_id] = @shop_process_id
  post[:number_of_payments] = options[:number_of_payments] || 1
  post[:recursive] = options[:recursive] || false

  add_invoice(post, money, options)
  add_card_data(post, payment)
  add_customer_data(post, options)

  commit(:pay_pci_buy_encrypted, post)
end

#remove_invalid_utf_8_byte_sequences(transcript) ⇒ Object


75
76
77
# File 'lib/active_merchant/billing/gateways/vpos.rb', line 75

def remove_invalid_utf_8_byte_sequences(transcript)
  transcript.encode('UTF-8', 'binary', undef: :replace, replace: '')
end

#scrub(transcript) ⇒ Object


68
69
70
71
72
73
# File 'lib/active_merchant/billing/gateways/vpos.rb', line 68

def scrub(transcript)
  clean_transcript = remove_invalid_utf_8_byte_sequences(transcript)
  clean_transcript.
    gsub(/(token\\":\\")[.\-\w]+/, '\1[FILTERED]').
    gsub(/(card_encrypted_data\\":\\")[.\-\w]+/, '\1[FILTERED]')
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)

64
65
66
# File 'lib/active_merchant/billing/gateways/vpos.rb', line 64

def supports_scrubbing?
  true
end

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


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

def void(_authorization, options = {})
  token = generate_token(@shop_process_id, 'rollback', '0.00')
  post = {
    token: token,
    shop_process_id: @shop_process_id
  }
  commit(:pci_buy_rollback, post)
end