Class: ActiveMerchant::Billing::WepayGateway

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

Constant Summary collapse

API_VERSION =
"2017-02-01"

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::DEBIT_CARDS, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

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

Returns a new instance of WepayGateway.



15
16
17
18
# File 'lib/active_merchant/billing/gateways/wepay.rb', line 15

def initialize(options = {})
  requires!(options, :client_id, :account_id, :access_token)
  super(options)
end

Instance Method Details

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



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/active_merchant/billing/gateways/wepay.rb', line 36

def authorize(money, payment_method, options = {})
  post = {}
  if payment_method.is_a?(String)
    authorize_with_token(post, money, payment_method, options)
  else
    MultiResponse.run do |r|
      r.process { store(payment_method, options) }
      r.process { authorize_with_token(post, money, r.authorization, options) }
    end
  end
end

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



48
49
50
51
52
53
54
55
56
57
# File 'lib/active_merchant/billing/gateways/wepay.rb', line 48

def capture(money, identifier, options = {})
  checkout_id, original_amount = split_authorization(identifier)

  post = {}
  post[:checkout_id] = checkout_id
  if(money && (original_amount != amount(money)))
    post[:amount] = amount(money)
  end
  commit('/checkout/capture', post, options)
end

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



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/active_merchant/billing/gateways/wepay.rb', line 20

def purchase(money, payment_method, options = {})
  post = {}
  if payment_method.is_a?(String)
    MultiResponse.run do |r|
      r.process { authorize_with_token(post, money, payment_method, options) }
      r.process { capture(money, r.authorization, options) }
    end
  else
    MultiResponse.run do |r|
      r.process { store(payment_method, options) }
      r.process { authorize_with_token(post, money, r.authorization, options) }
      r.process { capture(money, r.authorization, options) }
    end
  end
end

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



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/active_merchant/billing/gateways/wepay.rb', line 66

def refund(money, identifier, options = {})
  checkout_id, original_amount = split_authorization(identifier)

  post = {}
  post[:checkout_id] = checkout_id
  if(money && (original_amount != amount(money)))
    post[:amount] = amount(money)
  end
  post[:refund_reason] = (options[:description] || "Refund")
  post[:payer_email_message] = options[:payer_email_message] if options[:payer_email_message]
  post[:payee_email_message] = options[:payee_email_message] if options[:payee_email_message]
  commit("/checkout/refund", post, options)
end

#scrub(transcript) ⇒ Object



115
116
117
118
119
120
# File 'lib/active_merchant/billing/gateways/wepay.rb', line 115

def scrub(transcript)
  transcript.
    gsub(%r((\\?"cc_number\\?":\\?")[^\\"]+(\\?"))i, '\1[FILTERED]\2').
    gsub(%r((\\?"cvv\\?":\\?")[^\\"]+(\\?"))i, '\1[FILTERED]\2').
    gsub(%r((Authorization: Bearer )\w+)i, '\1[FILTERED]\2')
end

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



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/active_merchant/billing/gateways/wepay.rb', line 80

def store(creditcard, options = {})
  requires!(options, :email)

  post = {}
  post[:client_id] = @options[:client_id]
  post[:user_name] = "#{creditcard.first_name} #{creditcard.last_name}"
  post[:email] = options[:email] || "[email protected]"
  post[:cc_number] = creditcard.number
  post[:cvv] = creditcard.verification_value unless options[:recurring]
  post[:expiration_month] = creditcard.month
  post[:expiration_year] = creditcard.year
  post[:original_ip] = options[:ip] if options[:ip]
  post[:original_device] = options[:device_fingerprint] if options[:device_fingerprint]

  if(billing_address = (options[:billing_address] || options[:address]))
    post[:address] = {}
    post[:address]["address1"] = billing_address[:address1] if billing_address[:address1]
    post[:address]["city"]     = billing_address[:city] if billing_address[:city]
    post[:address]["country"]  = billing_address[:country]  if billing_address[:country]
    post[:address]["region"]   = billing_address[:state]  if billing_address[:state]
    post[:address]["postal_code"] = billing_address[:zip]
  end

  if options[:recurring] == true
    post[:client_secret] = @options[:client_secret]
    commit('/credit_card/transfer', post, options)
  else
    commit('/credit_card/create', post, options)
  end
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/active_merchant/billing/gateways/wepay.rb', line 111

def supports_scrubbing?
  true
end

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



59
60
61
62
63
64
# File 'lib/active_merchant/billing/gateways/wepay.rb', line 59

def void(identifier, options = {})
  post = {}
  post[:checkout_id] = split_authorization(identifier).first
  post[:cancel_reason] = (options[:description] || "Void")
  commit('/checkout/cancel', post, options)
end