authorizenetsample 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/CustomerProfiles/create-customer-payment-profile.rb +62 -0
- data/lib/CustomerProfiles/create-customer-profile-from-transaction.rb +51 -0
- data/lib/CustomerProfiles/create-customer-profile.rb +92 -0
- data/lib/CustomerProfiles/create-customer-shipping-address.rb +31 -0
- data/lib/CustomerProfiles/delete-customer-payment-profile.rb +32 -0
- data/lib/CustomerProfiles/delete-customer-profile.rb +31 -0
- data/lib/CustomerProfiles/delete-customer-shipping-address.rb +33 -0
- data/lib/CustomerProfiles/get-accept-customer-profile-page.rb +42 -0
- data/lib/CustomerProfiles/get-customer-payment-profile-list.rb +54 -0
- data/lib/CustomerProfiles/get-customer-payment-profile.rb +40 -0
- data/lib/CustomerProfiles/get-customer-profile-ids.rb +45 -0
- data/lib/CustomerProfiles/get-customer-profile.rb +54 -0
- data/lib/CustomerProfiles/get-customer-shipping-address.rb +41 -0
- data/lib/CustomerProfiles/update-customer-payment-profile.rb +37 -0
- data/lib/CustomerProfiles/update-customer-profile.rb +37 -0
- data/lib/CustomerProfiles/update-customer-shipping-address.rb +37 -0
- data/lib/CustomerProfiles/validate-customer-payment-profile.rb +37 -0
- data/lib/FraudManagement/approve-or-decline-held-transaction.rb +57 -0
- data/lib/FraudManagement/get-held-transaction-list.rb +47 -0
- data/lib/MobileInAppTransactions/create-an-accept-transaction.rb +59 -0
- data/lib/MobileInAppTransactions/create-an-android-pay-transaction.rb +59 -0
- data/lib/MobileInAppTransactions/create-an-apple-pay-transaction.rb +58 -0
- data/lib/PayPalExpressCheckout/authorization-and-capture-continued.rb +69 -0
- data/lib/PayPalExpressCheckout/authorization-and-capture.rb +70 -0
- data/lib/PayPalExpressCheckout/authorization-only-continued.rb +70 -0
- data/lib/PayPalExpressCheckout/authorization-only.rb +71 -0
- data/lib/PayPalExpressCheckout/credit.rb +67 -0
- data/lib/PayPalExpressCheckout/get-details.rb +69 -0
- data/lib/PayPalExpressCheckout/prior-authorization-capture.rb +112 -0
- data/lib/PayPalExpressCheckout/void.rb +113 -0
- data/lib/PaymentTransactions/authorize-credit-card.rb +103 -0
- data/lib/PaymentTransactions/capture-funds-authorized-through-another-channel.rb +60 -0
- data/lib/PaymentTransactions/capture-previously-authorized-amount.rb +104 -0
- data/lib/PaymentTransactions/charge-credit-card.rb +104 -0
- data/lib/PaymentTransactions/charge-customer-profile.rb +61 -0
- data/lib/PaymentTransactions/charge-tokenized-credit-card.rb +60 -0
- data/lib/PaymentTransactions/create-an-accept-payment-transaction.rb +62 -0
- data/lib/PaymentTransactions/credit-bank-account.rb +62 -0
- data/lib/PaymentTransactions/debit-bank-account.rb +64 -0
- data/lib/PaymentTransactions/get-an-accept-payment-page.rb +47 -0
- data/lib/PaymentTransactions/refund-transaction.rb +60 -0
- data/lib/PaymentTransactions/update-split-tender-group.rb +44 -0
- data/lib/PaymentTransactions/void-transaction.rb +103 -0
- data/lib/RecurringBilling/cancel-subscription.rb +36 -0
- data/lib/RecurringBilling/create-subscription-from-customer-profile.rb +52 -0
- data/lib/RecurringBilling/create-subscription.rb +54 -0
- data/lib/RecurringBilling/get-list-of-subscriptions.rb +51 -0
- data/lib/RecurringBilling/get-subscription-status.rb +36 -0
- data/lib/RecurringBilling/get-subscription.rb +42 -0
- data/lib/RecurringBilling/update-subscription.rb +54 -0
- data/lib/TransactionReporting/get-batch-statistics.rb +57 -0
- data/lib/TransactionReporting/get-customer-profile-transaction-list.rb +49 -0
- data/lib/TransactionReporting/get-merchant-details.rb +50 -0
- data/lib/TransactionReporting/get-settled-batch-list.rb +49 -0
- data/lib/TransactionReporting/get-transaction-details.rb +40 -0
- data/lib/TransactionReporting/get-transaction-list.rb +58 -0
- data/lib/TransactionReporting/get-unsettled-transaction-list.rb +48 -0
- data/lib/VisaCheckout/create-visa-checkout-transaction.rb +62 -0
- data/lib/VisaCheckout/decrypt-visa-checkout-data.rb +37 -0
- data/lib/authorize_netsample.rb +16 -0
- data/lib/authorizenetsample.rb +4 -0
- data/lib/credentials.yml +9 -0
- data/lib/spec/sample_code_spec.rb +320 -0
- data/lib/spec/spec.opts +2 -0
- data/lib/spec/spec_helper.rb +10 -0
- data/lib/spec/support/shared_helper.rb +7 -0
- metadata +110 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yaml'
|
3
|
+
require 'authorizenet'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
include AuthorizeNet::API
|
7
|
+
|
8
|
+
def get_customer_payment_profile(customerProfileId = '40036377', customerPaymentProfileId = '36315992')
|
9
|
+
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
|
10
|
+
|
11
|
+
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
|
12
|
+
|
13
|
+
|
14
|
+
request = GetCustomerPaymentProfileRequest.new
|
15
|
+
request.customerProfileId = customerProfileId
|
16
|
+
request.customerPaymentProfileId = customerPaymentProfileId
|
17
|
+
|
18
|
+
response = transaction.get_customer_payment_profile(request)
|
19
|
+
|
20
|
+
|
21
|
+
if response.messages.resultCode == MessageTypeEnum::Ok
|
22
|
+
puts "Successfully retrieved a payment profile with profile ID #{request.customerPaymentProfileId} and whose customer ID is #{request.customerProfileId}."
|
23
|
+
|
24
|
+
if response.paymentProfile.subscriptionIds != nil && response.paymentProfile.subscriptionIds.subscriptionId != nil
|
25
|
+
puts " List of subscriptions: "
|
26
|
+
response.paymentProfile.subscriptionIds.subscriptionId.each do |subscriptionId|
|
27
|
+
puts "#{subscriptionId}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
else
|
32
|
+
puts response.messages.messages[0].text
|
33
|
+
raise "Failed to get payment profile information with ID #{request.customerPaymentProfileId}."
|
34
|
+
end
|
35
|
+
return response
|
36
|
+
end
|
37
|
+
|
38
|
+
if __FILE__ == $0
|
39
|
+
get_customer_payment_profile()
|
40
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yaml'
|
3
|
+
require 'authorizenet'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
include AuthorizeNet::API
|
7
|
+
|
8
|
+
def get_customer_profile_ids()
|
9
|
+
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
|
10
|
+
|
11
|
+
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
|
12
|
+
|
13
|
+
|
14
|
+
request = GetCustomerProfileIdsRequest.new
|
15
|
+
|
16
|
+
response = transaction.get_customer_profile_ids(request)
|
17
|
+
|
18
|
+
|
19
|
+
if response.messages.resultCode == MessageTypeEnum::Ok
|
20
|
+
puts "Successfully retrieved customer IDs."
|
21
|
+
puts " Number of IDs returned: #{response.ids.numericString.count}"
|
22
|
+
# There's no paging options in this API request; the full list is returned every call.
|
23
|
+
# If the result set is going to be large, for this sample we'll break it down into smaller
|
24
|
+
# chunks so that we don't put 72,000 lines into a log file
|
25
|
+
puts " First 20 results:"
|
26
|
+
for profileId in 0..19 do
|
27
|
+
puts " #{response.ids.numericString[profileId]}"
|
28
|
+
end
|
29
|
+
# If we wanted to just return the whole list, we'd do something like this:
|
30
|
+
#
|
31
|
+
# response.ids.numericString.each do |id|
|
32
|
+
# puts id
|
33
|
+
# end
|
34
|
+
|
35
|
+
else
|
36
|
+
puts response.messages.messages[0].text
|
37
|
+
raise "Failed to get customer IDs."
|
38
|
+
end
|
39
|
+
return response
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
if __FILE__ == $0
|
44
|
+
get_customer_profile_ids()
|
45
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yaml'
|
3
|
+
require 'authorizenet'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
include AuthorizeNet::API
|
7
|
+
|
8
|
+
def get_customer_profile(customerProfileId = '40036377')
|
9
|
+
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
|
10
|
+
|
11
|
+
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
|
12
|
+
|
13
|
+
|
14
|
+
request = GetCustomerProfileRequest.new
|
15
|
+
request.customerProfileId = customerProfileId
|
16
|
+
|
17
|
+
response = transaction.get_customer_profile(request)
|
18
|
+
|
19
|
+
if response.messages.resultCode == MessageTypeEnum::Ok
|
20
|
+
puts "Successfully retrieved a customer with profile ID is #{request.customerProfileId} and whose customer ID is #{response.profile.merchantCustomerId}."
|
21
|
+
response.profile.paymentProfiles.each do |paymentProfile|
|
22
|
+
puts " Payment Profile ID #{paymentProfile.customerPaymentProfileId}"
|
23
|
+
puts " Payment Details:"
|
24
|
+
if paymentProfile.billTo != nil
|
25
|
+
puts " Last Name: #{paymentProfile.billTo.lastName}"
|
26
|
+
puts " Address: #{paymentProfile.billTo.address}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
response.profile.shipToList.each do |ship|
|
30
|
+
puts " Shipping Address ID #{ship.customerAddressId}"
|
31
|
+
puts " Shipping Details:"
|
32
|
+
puts " First Name: #{ship.firstName}"
|
33
|
+
puts " Last Name: #{ship.lastName}"
|
34
|
+
puts " Address: #{ship.address}"
|
35
|
+
end
|
36
|
+
|
37
|
+
if response.subscriptionIds != nil && response.subscriptionIds.subscriptionId != nil
|
38
|
+
puts " List of subscriptions: "
|
39
|
+
response.subscriptionIds.subscriptionId.each do |subscriptionId|
|
40
|
+
puts " #{subscriptionId}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
else
|
45
|
+
puts response.messages.messages[0].text
|
46
|
+
raise "Failed to get customer profile information with ID #{request.customerProfileId}"
|
47
|
+
end
|
48
|
+
return response
|
49
|
+
end
|
50
|
+
|
51
|
+
if __FILE__ == $0
|
52
|
+
get_customer_profile()
|
53
|
+
end
|
54
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yaml'
|
3
|
+
require 'authorizenet'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
include AuthorizeNet::API
|
7
|
+
|
8
|
+
def get_customer_shipping_address(customerProfileId = '40036377', customerAddressId = '37808097')
|
9
|
+
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
|
10
|
+
|
11
|
+
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
|
12
|
+
|
13
|
+
|
14
|
+
request = GetCustomerShippingAddressRequest.new
|
15
|
+
request.customerProfileId = customerProfileId
|
16
|
+
request.customerAddressId = customerAddressId
|
17
|
+
|
18
|
+
response = transaction.get_customer_shipping_profile(request)
|
19
|
+
|
20
|
+
|
21
|
+
if response.messages.resultCode == MessageTypeEnum::Ok
|
22
|
+
puts "Successfully retrieved a shipping address with profile ID #{request.customerAddressId} and whose customer ID is #{request.customerProfileId}."
|
23
|
+
|
24
|
+
if response.subscriptionIds != nil && response.subscriptionIds.subscriptionId != nil
|
25
|
+
puts " List of subscriptions: "
|
26
|
+
response.subscriptionIds.subscriptionId.each do |subscriptionId|
|
27
|
+
puts " #{subscriptionId}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
else
|
32
|
+
puts response.messages.messages[0].text
|
33
|
+
raise "Failed to get payment profile information with ID #{request.customerProfileId}"
|
34
|
+
end
|
35
|
+
return response
|
36
|
+
end
|
37
|
+
|
38
|
+
if __FILE__ == $0
|
39
|
+
get_customer_shipping_address()
|
40
|
+
end
|
41
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yaml'
|
3
|
+
require 'authorizenet'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
include AuthorizeNet::API
|
7
|
+
|
8
|
+
def update_customer_payment_profile(customerProfileId = '35894174', customerPaymentProfileId = '33605803')
|
9
|
+
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
|
10
|
+
|
11
|
+
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
|
12
|
+
|
13
|
+
request = UpdateCustomerPaymentProfileRequest.new
|
14
|
+
|
15
|
+
payment = PaymentType.new(CreditCardType.new('4111111111111111','2025-05'))
|
16
|
+
profile = CustomerPaymentProfileExType.new(nil,nil,payment,nil,nil)
|
17
|
+
|
18
|
+
request.paymentProfile = profile
|
19
|
+
request.customerProfileId = customerProfileId
|
20
|
+
profile.customerPaymentProfileId = customerPaymentProfileId
|
21
|
+
|
22
|
+
response = transaction.update_customer_payment_profile(request)
|
23
|
+
|
24
|
+
|
25
|
+
if response.messages.resultCode == MessageTypeEnum::Ok
|
26
|
+
puts "Successfully updated customer payment profile with ID #{request.paymentProfile.customerPaymentProfileId}."
|
27
|
+
else
|
28
|
+
puts response.messages.messages[0].text
|
29
|
+
raise "Failed to update customer with customer payment profile ID #{request.paymentProfile.customerPaymentProfileId}."
|
30
|
+
end
|
31
|
+
return response
|
32
|
+
end
|
33
|
+
|
34
|
+
if __FILE__ == $0
|
35
|
+
update_customer_payment_profile()
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yaml'
|
3
|
+
require 'authorizenet'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
include AuthorizeNet::API
|
7
|
+
|
8
|
+
def update_customer_profile(customerProfileId = '35704713')
|
9
|
+
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
|
10
|
+
|
11
|
+
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
|
12
|
+
|
13
|
+
|
14
|
+
request = UpdateCustomerProfileRequest.new
|
15
|
+
request.profile = CustomerProfileExType.new
|
16
|
+
|
17
|
+
#Edit this part to select a specific customer
|
18
|
+
request.profile.customerProfileId = customerProfileId
|
19
|
+
request.profile.merchantCustomerId = "mycustomer"
|
20
|
+
request.profile.description = "john doe"
|
21
|
+
request.profile.email = "email@email.com"
|
22
|
+
response = transaction.update_customer_profile(request)
|
23
|
+
|
24
|
+
|
25
|
+
if response.messages.resultCode == MessageTypeEnum::Ok
|
26
|
+
puts "Successfully updated customer with customer profile ID #{request.profile.customerProfileId}."
|
27
|
+
else
|
28
|
+
puts response.messages.messages[0].text
|
29
|
+
raise "Failed to update customer with customer profile ID #{request.profile.customerProfileId}."
|
30
|
+
end
|
31
|
+
return response
|
32
|
+
end
|
33
|
+
|
34
|
+
if __FILE__ == $0
|
35
|
+
update_customer_profile()
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yaml'
|
3
|
+
require 'authorizenet'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
include AuthorizeNet::API
|
7
|
+
|
8
|
+
def update_customer_shipping_address(customerProfileId = '35894174', customerAddressId = '35745790')
|
9
|
+
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
|
10
|
+
|
11
|
+
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
|
12
|
+
|
13
|
+
|
14
|
+
request = UpdateCustomerShippingAddressRequest.new
|
15
|
+
|
16
|
+
|
17
|
+
request.address = CustomerAddressExType.new('John','Doe','Anet','800 N 106th')
|
18
|
+
|
19
|
+
#Edit this part to select a specific customer
|
20
|
+
request.address.customerAddressId = customerAddressId
|
21
|
+
request.customerProfileId = customerProfileId
|
22
|
+
|
23
|
+
response = transaction.update_customer_shipping_profile(request)
|
24
|
+
|
25
|
+
|
26
|
+
if response.messages.resultCode == MessageTypeEnum::Ok
|
27
|
+
puts "Successfully updated customer with customer profile ID #{request.address.customerAddressId}."
|
28
|
+
else
|
29
|
+
puts response.messages.messages[0].text
|
30
|
+
raise "Failed to update customer with customer profile ID #{request.address.customerAddressId}."
|
31
|
+
end
|
32
|
+
return response
|
33
|
+
end
|
34
|
+
|
35
|
+
if __FILE__ == $0
|
36
|
+
update_customer_shipping_address()
|
37
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yaml'
|
3
|
+
require 'authorizenet'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
include AuthorizeNet::API
|
7
|
+
|
8
|
+
def validate_customer_payment_profile(customerProfileId = '36152115', customerPaymentProfileId = '32689262')
|
9
|
+
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
|
10
|
+
|
11
|
+
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
|
12
|
+
|
13
|
+
request = ValidateCustomerPaymentProfileRequest.new
|
14
|
+
|
15
|
+
#Edit this part to select a specific customer
|
16
|
+
request.customerProfileId = customerProfileId
|
17
|
+
request.customerPaymentProfileId = customerPaymentProfileId
|
18
|
+
request.validationMode = ValidationModeEnum::TestMode
|
19
|
+
|
20
|
+
response = transaction.validate_customer_payment_profile(request)
|
21
|
+
|
22
|
+
if response.messages.resultCode == MessageTypeEnum::Ok
|
23
|
+
puts "Successfully validated customer with customer profile ID #{request.customerProfileId}"
|
24
|
+
puts "Direct Response: #{response.directResponse} "
|
25
|
+
else
|
26
|
+
puts response.messages.messages[0].code
|
27
|
+
puts response.messages.messages[0].text
|
28
|
+
raise "Failed to validate customer with customer profile ID #{request.customerProfileId} and payment profile ID #{customerPaymentProfileId}"
|
29
|
+
end
|
30
|
+
|
31
|
+
return response
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
if __FILE__ == $0
|
36
|
+
validate_customer_payment_profile()
|
37
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yaml'
|
3
|
+
require 'authorizenet'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
include AuthorizeNet::API
|
7
|
+
|
8
|
+
def approve_or_decline_held_transaction(refTransId)
|
9
|
+
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
|
10
|
+
|
11
|
+
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
|
12
|
+
|
13
|
+
request = UpdateHeldTransactionRequest.new
|
14
|
+
|
15
|
+
request.heldTransactionRequest = HeldTransactionRequestType.new()
|
16
|
+
request.heldTransactionRequest.action = AfdsTransactionEnum::Approve
|
17
|
+
request.heldTransactionRequest.refTransId = "60012148061"
|
18
|
+
|
19
|
+
response = transaction.update_held_transaction(request)
|
20
|
+
|
21
|
+
if response != nil
|
22
|
+
if response.messages.resultCode == MessageTypeEnum::Ok
|
23
|
+
if response.transactionResponse != nil && response.transactionResponse.messages != nil
|
24
|
+
puts "Successfully updated transaction: #{response.transactionResponse.authCode})"
|
25
|
+
puts "Transaction Response code: #{response.transactionResponse.responseCode}"
|
26
|
+
puts "Code: #{response.transactionResponse.messages.messages[0].code}"
|
27
|
+
puts "Description: #{response.transactionResponse.messages.messages[0].description}"
|
28
|
+
else
|
29
|
+
puts "Update Transaction Failed"
|
30
|
+
if response.transactionResponse.errors != nil
|
31
|
+
puts "Error Code: #{response.transactionResponse.errors.errors[0].errorCode}"
|
32
|
+
puts "Error Message: #{response.transactionResponse.errors.errors[0].errorText}"
|
33
|
+
end
|
34
|
+
raise "Failed to update transaction."
|
35
|
+
end
|
36
|
+
else
|
37
|
+
puts "Update transaction Failed"
|
38
|
+
if response.transactionResponse != nil && response.transactionResponse.errors != nil
|
39
|
+
puts "Error Code: #{response.transactionResponse.errors.errors[0].errorCode}"
|
40
|
+
puts "Error Message: #{response.transactionResponse.errors.errors[0].errorText}"
|
41
|
+
else
|
42
|
+
puts "Error Code: #{response.messages.messages[0].code}"
|
43
|
+
puts "Error Message: #{response.messages.messages[0].text}"
|
44
|
+
end
|
45
|
+
raise "Failed to update transaction."
|
46
|
+
end
|
47
|
+
else
|
48
|
+
puts "Response is null"
|
49
|
+
raise "Failed to update transaction."
|
50
|
+
end
|
51
|
+
|
52
|
+
return response
|
53
|
+
end
|
54
|
+
|
55
|
+
if __FILE__ == $0
|
56
|
+
update_held_transaction("12345")
|
57
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yaml'
|
3
|
+
require 'authorizenet'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
include AuthorizeNet::API
|
7
|
+
|
8
|
+
def get_held_transaction_List()
|
9
|
+
|
10
|
+
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
|
11
|
+
#merchant information
|
12
|
+
transaction = AuthorizeNet::API::Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
|
13
|
+
|
14
|
+
request = GetUnsettledTransactionListRequest.new
|
15
|
+
|
16
|
+
request.status = TransactionGroupStatusEnum::PENDINGAPPROVAL;
|
17
|
+
request.paging = Paging.new;
|
18
|
+
request.paging.limit = 10;
|
19
|
+
request.paging.offset = 1;
|
20
|
+
|
21
|
+
request.sorting = TransactionListSorting.new;
|
22
|
+
request.sorting.orderBy = TransactionListOrderFieldEnum::Id;
|
23
|
+
request.sorting.orderDescending = true;
|
24
|
+
|
25
|
+
response = transaction.get_unsettled_transaction_list(request)
|
26
|
+
|
27
|
+
if response.messages.resultCode == MessageTypeEnum::Ok
|
28
|
+
unsettled_transactions = response.transactions
|
29
|
+
|
30
|
+
response.transactions.transaction.each do |unsettled_transaction|
|
31
|
+
puts "Transaction #{unsettled_transaction.transId} was submitted at #{unsettled_transaction.submitTimeUTC}"
|
32
|
+
|
33
|
+
end
|
34
|
+
puts "Total transaction received #{unsettled_transactions.transaction.length}"
|
35
|
+
else
|
36
|
+
puts "ERROR message: #{response.messages.messages[0].text}"
|
37
|
+
puts "ERROR code: #{response.messages.messages[0].code}"
|
38
|
+
raise "Failed to get unsettled transaction list."
|
39
|
+
end
|
40
|
+
|
41
|
+
return response
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
if __FILE__ == $0
|
46
|
+
get_unsettled_transaction_List()
|
47
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yaml'
|
3
|
+
require 'authorizenet'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
include AuthorizeNet::API
|
7
|
+
|
8
|
+
def create_an_accept_transaction()
|
9
|
+
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
|
10
|
+
|
11
|
+
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
|
12
|
+
|
13
|
+
request = CreateTransactionRequest.new
|
14
|
+
request.transactionRequest = TransactionRequestType.new()
|
15
|
+
request.transactionRequest.amount = ((SecureRandom.random_number + 1 ) * 150 ).round(2)
|
16
|
+
request.transactionRequest.payment = PaymentType.new
|
17
|
+
request.transactionRequest.payment.opaqueData = OpaqueDataType.new('COMMON.ACCEPT.INAPP.PAYMENT','9479246682350209005001',nil)
|
18
|
+
|
19
|
+
request.transactionRequest.transactionType = TransactionTypeEnum::AuthCaptureTransaction
|
20
|
+
|
21
|
+
response = transaction.create_transaction(request)
|
22
|
+
|
23
|
+
if response != nil
|
24
|
+
if response.messages.resultCode == MessageTypeEnum::Ok
|
25
|
+
if response.transactionResponse != nil && response.transactionResponse.messages != nil
|
26
|
+
puts "Successfully made a purchase (authorization code: #{response.transactionResponse.authCode})"
|
27
|
+
puts "Transaction Response code: #{response.transactionResponse.responseCode}"
|
28
|
+
puts "Code: #{response.transactionResponse.messages.messages[0].code}"
|
29
|
+
puts "Description: #{response.transactionResponse.messages.messages[0].description}"
|
30
|
+
else
|
31
|
+
puts "Transaction Failed"
|
32
|
+
if response.transactionResponse.errors != nil
|
33
|
+
puts "Error Code: #{response.transactionResponse.errors.errors[0].errorCode}"
|
34
|
+
puts "Error Message: #{response.transactionResponse.errors.errors[0].errorText}"
|
35
|
+
end
|
36
|
+
raise "Failed to make a purchase."
|
37
|
+
end
|
38
|
+
else
|
39
|
+
puts "Transaction Failed"
|
40
|
+
if response.transactionResponse != nil && response.transactionResponse.errors != nil
|
41
|
+
puts "Error Code: #{response.transactionResponse.errors.errors[0].errorCode}"
|
42
|
+
puts "Error Message: #{response.transactionResponse.errors.errors[0].errorText}"
|
43
|
+
else
|
44
|
+
puts "Error Code: #{response.messages.messages[0].code}"
|
45
|
+
puts "Error Message: #{response.messages.messages[0].text}"
|
46
|
+
end
|
47
|
+
raise "Failed to make a purchase."
|
48
|
+
end
|
49
|
+
else
|
50
|
+
puts "Response is null"
|
51
|
+
raise "Failed to make a purchase."
|
52
|
+
end
|
53
|
+
|
54
|
+
return response
|
55
|
+
end
|
56
|
+
|
57
|
+
if __FILE__ == $0
|
58
|
+
create_an_accept_transaction()
|
59
|
+
end
|