Class: ActiveMerchant::Billing::WepayGateway

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

Constant Summary

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.



13
14
15
16
# File 'lib/active_merchant/billing/gateways/wepay.rb', line 13

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

Instance Method Details

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



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

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



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

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



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

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



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

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



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

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



78
79
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
# File 'lib/active_merchant/billing/gateways/wepay.rb', line 78

def store(creditcard, options = {})
  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

  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
    post[:original_device] = options[:device_fingerprint] if options[:device_fingerprint]
    post[:original_ip] = options[:ip] if options[:ip]
    commit('/credit_card/create', post, options)
  end
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/active_merchant/billing/gateways/wepay.rb', line 107

def supports_scrubbing?
  true
end

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



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

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