Class: TransactionGateway::AuthorizeNetGateway
Constant Summary
Constants inherited
from Result
Result::AUTHORIZEDOTNET, Result::BRAINTREE, Result::FORTIS
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#create_card_account(card, customer_profile_id) ⇒ Object
-
#create_customer_profile(customer, card = nil) ⇒ Object
-
#create_transaction(card_or_profile, amount, settle = false) ⇒ Object
-
#force_settle(profile, authorize_code, amount) ⇒ Object
-
#initialize(login_id, transaction_key, environment = :sandbox) ⇒ AuthorizeNetGateway
constructor
A new instance of AuthorizeNetGateway.
-
#refund(profile, amount) ⇒ Object
-
#settle_transaction(transaction_id, amount = nil) ⇒ Object
-
#void_transaction(transaction_id) ⇒ Object
Methods inherited from Result
#handle_result
Constructor Details
#initialize(login_id, transaction_key, environment = :sandbox) ⇒ AuthorizeNetGateway
Returns a new instance of AuthorizeNetGateway.
28
29
30
31
32
33
34
|
# File 'lib/transaction_gateway/authorize_net_gateway.rb', line 28
def initialize(login_id, transaction_key, environment = :sandbox)
self.login_id = login_id
self.transaction_key = transaction_key
environment = environment.to_s.gsub(/\s/, '').downcase
self.gateway = (environment == "") ? :sandbox : environment.to_sym
end
|
Instance Attribute Details
#gateway ⇒ Object
Returns the value of attribute gateway.
16
17
18
|
# File 'lib/transaction_gateway/authorize_net_gateway.rb', line 16
def gateway
@gateway
end
|
#login_id ⇒ Object
Returns the value of attribute login_id.
16
17
18
|
# File 'lib/transaction_gateway/authorize_net_gateway.rb', line 16
def login_id
@login_id
end
|
#transaction_key ⇒ Object
Returns the value of attribute transaction_key.
16
17
18
|
# File 'lib/transaction_gateway/authorize_net_gateway.rb', line 16
def transaction_key
@transaction_key
end
|
Class Method Details
.gateway_url(environment = :sandbox) ⇒ Object
36
37
38
39
40
|
# File 'lib/transaction_gateway/authorize_net_gateway.rb', line 36
def self.gateway_url(environment = :sandbox)
environment = environment.to_s.gsub(/\s/, "").downcase
environment = "sandbox" if environment == ""
return AuthorizeNet::XmlTransaction.new("","", :gateway => environment.to_sym).instance_variable_get(:@gateway)
end
|
Instance Method Details
#create_card_account(card, customer_profile_id) ⇒ Object
103
104
105
106
107
108
109
110
111
|
# File 'lib/transaction_gateway/authorize_net_gateway.rb', line 103
def create_card_account(card, customer_profile_id)
raise TransactionGatewayInvalidCardType unless card.class == GatewayCard
transaction = get_cim_transaction_object
payment_profile = AuthorizeNet::CIM::PaymentProfile.new(:payment_method => card.authorize_net_credit_card)
result = transaction.create_payment_profile(payment_profile, customer_profile_id)
return handle_result(result, AUTHORIZEDOTNET)
end
|
#create_customer_profile(customer, card = nil) ⇒ Object
94
95
96
97
98
99
100
101
|
# File 'lib/transaction_gateway/authorize_net_gateway.rb', line 94
def create_customer_profile(customer, card = nil)
raise InvalidCustomerType unless customer.class == GatewayCustomer
transaction = get_cim_transaction_object
result = transaction.create_profile(customer.convert_to_authorize_net_input(card), {:validation_mode => :liveMode})
return handle_result(result, AUTHORIZEDOTNET)
end
|
#create_transaction(card_or_profile, amount, settle = false) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/transaction_gateway/authorize_net_gateway.rb', line 42
def create_transaction(card_or_profile, amount, settle = false)
raise TransactionGatewayInvalidAmount if amount.to_f <= 0
case card_or_profile
when GatewayCard
transaction = get_aim_transaction_object
if settle == true
result = transaction.purchase(amount, card_or_profile.authorize_net_credit_card)
else
result = transaction.authorize(amount, card_or_profile.authorize_net_credit_card)
end
when GatewayCustomerProfile
transaction = get_cim_transaction_object
type = :auth_only
type = :prior_auth_capture if settle == true
result = transaction.create_transaction(type, amount, card_or_profile.profile_id.to_s, card_or_profile.payment_profile_id.to_s, nil)
else
raise TransactionGatewayInvalidCardType
end
return handle_result(result, AUTHORIZEDOTNET)
end
|
#force_settle(profile, authorize_code, amount) ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/transaction_gateway/authorize_net_gateway.rb', line 113
def force_settle(profile, authorize_code, amount)
raise InvalidPaymentProfileType unless profile.class == GatewayCustomerProfile
raise TransactionGatewayInvalidAmount if amount.to_f <= 0
transaction = get_cim_transaction_object
transaction.set_fields( {:auth_code => authorize_code})
result = transaction.create_transaction(:capture_only, amount, profile.profile_id.to_s, profile.payment_profile_id.to_s, nil)
return handle_result(result, AUTHORIZEDOTNET)
end
|
#refund(profile, amount) ⇒ Object
78
79
80
81
82
83
84
85
86
|
# File 'lib/transaction_gateway/authorize_net_gateway.rb', line 78
def refund(profile, amount)
raise InvalidPaymentProfileType unless profile.class == GatewayCustomerProfile
raise TransactionGatewayInvalidAmount if amount.to_f == 0
transaction = get_cim_transaction_object
result = transaction.create_transaction(:refund, amount.abs, profile.profile_id.to_s, profile.payment_profile_id.to_s, nil)
return handle_result(result, AUTHORIZEDOTNET)
end
|
#settle_transaction(transaction_id, amount = nil) ⇒ Object
68
69
70
71
72
73
74
75
76
|
# File 'lib/transaction_gateway/authorize_net_gateway.rb', line 68
def settle_transaction(transaction_id, amount = nil)
raise TransactionIDInvalid if transaction_id.to_s.gsub(/\s/, "") == ""
capture_transaction = get_aim_transaction_object
result = capture_transaction.prior_auth_capture(transaction_id, amount)
return handle_result(result, AUTHORIZEDOTNET)
end
|
#void_transaction(transaction_id) ⇒ Object
88
89
90
91
92
|
# File 'lib/transaction_gateway/authorize_net_gateway.rb', line 88
def void_transaction(transaction_id)
transaction = get_aim_transaction_object
result = transaction.void(transaction_id)
return handle_result(result, AUTHORIZEDOTNET)
end
|