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::CURRENCIES_WITHOUT_FRACTIONS, 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, non_fractional_currency?, #scrub, supported_countries, #supported_countries, supported_countries=, supports?, #supports_scrubbing?, #test?

Methods included from CreditCardFormatting

#expdate, #format

Constructor Details

#initialize(options = {}) ⇒ 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


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

def authorize(money, payment_method, options = {})
  post = {auto_capture: 0}
  if payment_method.is_a?(String)
    purchase_with_token(post, money, payment_method, options)
  else
    MultiResponse.run do |r|
      r.process { store(payment_method, options) }
      r.process { purchase_with_token(post, money, split_authorization(r.authorization).first, options) }
    end
  end
end

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


42
43
44
45
46
# File 'lib/active_merchant/billing/gateways/wepay.rb', line 42

def capture(money, identifier, options = {})
  post = {}
  post[:checkout_id] = split_authorization(identifier).first
  commit('/checkout/capture', post)
end

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


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

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

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


55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/active_merchant/billing/gateways/wepay.rb', line 55

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[:app_fee] = options[:application_fee] if options[:application_fee]
  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)
end

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


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

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]
  post[:cc_number] = creditcard.number
  post[:cvv] = creditcard.verification_value
  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] = {
      "address1" => billing_address[:address1],
      "city"     => billing_address[:city],
      "state"    => billing_address[:state],
      "country"  => billing_address[:country]
    }
    if(post[:country] == "US")
      post[:address]["zip"] = billing_address[:zip]
    else
      post[:address]["postcode"] = billing_address[:zip]
    end
  end
  commit('/credit_card/create', post)
end

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


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

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