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
33
# 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]
  @encryption_key = OpenSSL::PKey::RSA.new(options[:encryption_key]) if options[:encryption_key]
  @shop_process_id = options[:shop_process_id] || SecureRandom.random_number(10**15)
  super
end

Instance Method Details

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



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/active_merchant/billing/gateways/vpos.rb', line 67

def credit(money, payment, options = {})
  # Not permitted for foreign cards.
  commerce = options[:commerce] || @options[:commerce]
  commerce_branch = options[:commerce_branch] || @options[:commerce_branch]

  token = generate_token(@shop_process_id, 'refund', commerce, commerce_branch, amount(money), currency(money))
  post = {}
  post[:token] = token
  post[:commerce] = commerce.to_i
  post[:commerce_branch] = commerce_branch.to_i
  post[:shop_process_id] = @shop_process_id
  add_invoice(post, money, options)
  add_card_data(post, payment)
  add_customer_data(post, options)
  post[:origin_shop_process_id] = options[:original_shop_process_id] if options[:original_shop_process_id]
  commit(:refund, post)
end

#one_time_public_keyObject

Required to encrypt PAN data.



119
120
121
122
123
# File 'lib/active_merchant/billing/gateways/vpos.rb', line 119

def one_time_public_key
  token = generate_token('get_encription_public_key', @public_key)
  response = commit(:pci_encryption_key, token: token)
  response.params['encryption_key']
end

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



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

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

  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

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



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/active_merchant/billing/gateways/vpos.rb', line 85

def refund(money, authorization, options = {})
  commerce = options[:commerce] || @options[:commerce]
  commerce_branch = options[:commerce_branch] || @options[:commerce_branch]
  shop_process_id = options[:shop_process_id] || @shop_process_id
  _, original_shop_process_id = authorization.to_s.split('#')

  token = generate_token(shop_process_id, 'refund', commerce, commerce_branch, amount(money), currency(money))
  post = {}
  post[:token] = token
  post[:commerce] = commerce.to_i
  post[:commerce_branch] = commerce_branch.to_i
  post[:shop_process_id] = shop_process_id
  add_invoice(post, money, options)
  add_customer_data(post, options)
  post[:origin_shop_process_id] = original_shop_process_id || options[:original_shop_process_id]
  commit(:refund, post)
end

#remove_invalid_utf_8_byte_sequences(transcript) ⇒ Object



114
115
116
# File 'lib/active_merchant/billing/gateways/vpos.rb', line 114

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

#scrub(transcript) ⇒ Object



107
108
109
110
111
112
# File 'lib/active_merchant/billing/gateways/vpos.rb', line 107

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)


103
104
105
# File 'lib/active_merchant/billing/gateways/vpos.rb', line 103

def supports_scrubbing?
  true
end

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



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

def void(authorization, options = {})
  _, shop_process_id = authorization.to_s.split('#')
  token = generate_token(shop_process_id, 'rollback', '0.00')
  post = {
    token: token,
    shop_process_id: shop_process_id
  }
  commit(:pci_buy_rollback, post)
end