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::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, #strftime_yyyymm

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
# 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
  post[:amount] = amount(money) if money && (original_amount != amount(money))
  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



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/active_merchant/billing/gateways/wepay.rb', line 62

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

  post = {}
  post[:checkout_id] = checkout_id
  post[:amount] = amount(money) if money && (original_amount != amount(money))
  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



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

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



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/active_merchant/billing/gateways/wepay.rb', line 74

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)


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

def supports_scrubbing?
  true
end

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



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

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