Class: ActiveMerchant::Billing::NetbanxGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/netbanx.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

#format

Methods included from PostsData

included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request

Constructor Details

#initialize(options = {}) ⇒ NetbanxGateway

Returns a new instance of NetbanxGateway.



25
26
27
28
# File 'lib/active_merchant/billing/gateways/netbanx.rb', line 25

def initialize(options={})
  requires!(options, :account_number, :api_key)
  super
end

Instance Method Details

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



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

def authorize(money, payment, options={})
  # Do a Verification with AVS prior to Auth + Settle
  verification_response = verify(payment, options)
  return verification_response if verification_response.message != 'OK'

  post = {}
  add_invoice(post, money, options)
  add_payment(post, payment, options)

  commit(:post, 'auths', post)
end

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



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

def capture(money, authorization, options={})
  post = {}
  add_invoice(post, money, options)

  commit(:post, "auths/#{authorization}/settlements", post)
end

#get_settlement(authorization) ⇒ Object



84
85
86
87
# File 'lib/active_merchant/billing/gateways/netbanx.rb', line 84

def get_settlement(authorization)
  post = {}
  commit(:get, "settlements/#{authorization}", post)
end

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



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

def purchase(money, payment, options={})
  # Do a Verification with AVS prior to purchase
  verification_response = verify(payment, options)
  return verification_response if verification_response.message != 'OK'

  post = {}
  add_invoice(post, money, options)
  add_settle_with_auth(post)
  add_payment(post, payment, options)

  commit(:post, 'auths', post)
end

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



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/active_merchant/billing/gateways/netbanx.rb', line 62

def refund(money, authorization, options={})
  # If the transactions that are pending, API call needs to be Cancellation
  settlement_data = get_settlement(authorization)
  return settlement_data if settlement_data.message != 'OK'

  post = {}
  if settlement_data.params['status'] == 'PENDING' && money == settlement_data.params['amount']
    post[:status] = 'CANCELLED'
    commit(:put, "settlements/#{authorization}", post)
  elsif settlement_data.params['status'] == 'PENDING' && (money < settlement_data.params['amount'] || money > settlement_data.params['amount'])
    return Response.new(false, 'Transaction not settled. Either do a full refund or try partial refund after settlement.')
  else
    add_invoice(post, money, options)

    # Setting merchantRefNumber to a unique id for each refund
    # This is to support multiple partial refunds for the same order
    post[:merchantRefNum] = SecureRandom.uuid

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

#scrub(transcript) ⇒ Object



132
133
134
135
136
137
# File 'lib/active_merchant/billing/gateways/netbanx.rb', line 132

def scrub(transcript)
  transcript.
    gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
    gsub(%r(("card\\?":{\\?"cardNum\\?":\\?")\d+), '\1[FILTERED]').
    gsub(%r(("cvv\\?":\\?")\d+), '\1[FILTERED]')
end

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

note: when passing options we only attempt to add the

card to the profile_id passed as the options[:customer]


106
107
108
109
110
111
112
113
114
# File 'lib/active_merchant/billing/gateways/netbanx.rb', line 106

def store(credit_card, options={})
  # locale can only be one of en_US, fr_CA, en_GB
  requires!(options, :locale)
  post = {}
  add_credit_card(post, credit_card, options)
  add_customer_data(post, options)

  commit(:post, 'customervault/v1/profiles', post)
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/active_merchant/billing/gateways/netbanx.rb', line 128

def supports_scrubbing?
  true
end

#unstore(identification, options = {}) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/active_merchant/billing/gateways/netbanx.rb', line 116

def unstore(identification, options = {})
  customer_id, card_id = identification.split('|')

  if card_id.nil?
    # deleting the profile
    commit(:delete, "customervault/v1/profiles/#{CGI.escape(customer_id)}", nil)
  else
    # deleting the card from the profile
    commit(:delete, "customervault/v1/profiles/#{CGI.escape(customer_id)}/cards/#{CGI.escape(card_id)}", nil)
  end
end

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



96
97
98
99
100
101
102
# File 'lib/active_merchant/billing/gateways/netbanx.rb', line 96

def verify(credit_card, options={})
  post = {}
  add_payment(post, credit_card, options)
  add_order_id(post, options)

  commit(:post, 'verifications', post)
end

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



89
90
91
92
93
94
# File 'lib/active_merchant/billing/gateways/netbanx.rb', line 89

def void(authorization, options={})
  post = {}
  add_order_id(post, options)

  commit(:post, "auths/#{authorization}/voidauths", post)
end