Class: ActiveMerchant::Billing::UsaEpaySoapGateway

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

Constant Summary

Constants inherited from Gateway

Gateway::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, inherited, supports?, #test?

Methods included from Utils

generate_unique_id

Methods included from CreditCardFormatting

#format

Methods included from RequiresParameters

#requires!

Methods included from PostsData

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

Constructor Details

#initialize(options = {}) ⇒ UsaEpaySoapGateway

Returns a new instance of UsaEpaySoapGateway.



12
13
14
15
16
17
18
19
20
21
# File 'lib/active_merchant/billing/gateways/usa_epay_soap.rb', line 12

def initialize(options = {})
  requires!(options, :login)
  requires!(options, :password)
  @options = options
  
  PaySimple.key = options[:login]
  PaySimple.pin = options[:password]
  
  super
end

Instance Method Details

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



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

def purchase(money, customer_number, options = {})
  success = false
  begin
    
    @paysimple_response = PaySimple::Subscription.charge(customer_number, :Amount => sprintf("%.2f", money.to_f/100))
    
    if @paysimple_response["Result"] == "Approved"
      success = true
    end
  rescue Exception => @error
    puts "An error occurred: #{@error.message}"
  end
  
  parse_paysimple_response(success, @paysimple_response) 
  
end

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



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/active_merchant/billing/gateways/usa_epay_soap.rb', line 23

def store(creditcard, options = {})

  @error = nil
  begin
    @paysimple_response = PaySimple::Subscription.create(
      :CustomerID  => "#{Time.now.to_i}#{rand(999999)}",
      :BillingAddress => {
        :FirstName => creditcard.first_name,
        :LastName => creditcard.last_name
      },
      :CreditCardData => {
        :CardNumber => creditcard.number,
        :CardExpiration => expdate(creditcard)
      }, 
      :Schedule => :monthly,
      :Next => "2008-09-05", # in the past, paysimple seems to need this
      :Enabled => false
    )
  rescue Exception => @error
    puts "An error occurred: #{@error.message}"
  end
  
  success = @error ? false : true
  
  message = @paysimple_response
  if @error
    message = @error
  end
  
  USAEpaySoapResponse.new(success == true, message, {:token => @paysimple_response})
  
end

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



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/active_merchant/billing/gateways/usa_epay_soap.rb', line 73

def unstore(customer_number, options={})
  @error = nil
  begin
    @paysimple_response = PaySimple::Subscription.delete(customer_number)
  
    puts "Subscription removed from active use."
  rescue Exception => @error
    puts "An error occurred: #{@error.message}"
  end

  success = @error ? false : true
  message = @paysimple_response
  if @error
    message = @error
  end
  
  USAEpaySoapResponse.new(success == true, message, {:token => @paysimple_response})
  
end

#update(customer_number, creditcard, options = {}) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/active_merchant/billing/gateways/usa_epay_soap.rb', line 93

def update(customer_number, creditcard, options = {})
  @error = nil
  begin
    @paysimple_response = PaySimple::Subscription.update(
      customer_number,
      :CreditCardData => {
        :CardNumber => creditcard.number,
        :CardExpiration => expdate(creditcard)
      }
    )

  rescue Exception => @error
    puts "An error occurred: #{@error.message}"
  end
  
  success = @error ? false : true
  
  parse_paysimple_response(success, @paysimple_response.to_s) 

end