-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcredit.rb
61 lines (53 loc) · 2.31 KB
/
credit.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
55
56
57
58
59
60
61
require 'cybersource_rest_client'
require_relative '../../../data/Configuration.rb'
public
class Credit
def run()
request_obj = CyberSource::CreateCreditRequest.new
client_reference_information = CyberSource::Ptsv2paymentsClientReferenceInformation.new
client_reference_information.code = "12345678"
request_obj.client_reference_information = client_reference_information
payment_information = CyberSource::Ptsv2paymentsidrefundsPaymentInformation.new
card = CyberSource::Ptsv2paymentsidrefundsPaymentInformationCard.new
card.number = "4111111111111111"
card.expiration_month = "03"
card.expiration_year = "2031"
card.type = "001"
payment_information.card = card
request_obj.payment_information = payment_information
order_information = CyberSource::Ptsv2paymentsidrefundsOrderInformation.new
amount_details = CyberSource::Ptsv2paymentsidcapturesOrderInformationAmountDetails.new
amount_details.total_amount = "200"
amount_details.currency = "usd"
order_information.amount_details = amount_details
bill_to = CyberSource::Ptsv2paymentsidcapturesOrderInformationBillTo.new
bill_to.first_name = "John"
bill_to.last_name = "Deo"
bill_to.address1 = "900 Metro Center Blvd"
bill_to.locality = "Foster City"
bill_to.administrative_area = "CA"
bill_to.postal_code = "48104-2201"
bill_to.country = "US"
bill_to.email = "test@cybs.com"
bill_to.phone_number = "9321499232"
order_information.bill_to = bill_to
request_obj.order_information = order_information
config = MerchantConfiguration.new.merchantConfigProp()
api_client = CyberSource::ApiClient.new
api_instance = CyberSource::CreditApi.new(api_client, config)
data, status_code, headers = api_instance.create_credit(request_obj)
puts data, status_code, headers
write_log_audit(status_code)
return data
rescue StandardError => err
write_log_audit(err.code)
puts err.message
end
def write_log_audit(status)
filename = ($0.split("/")).last.split(".")[0]
puts "[Sample Code Testing] [#{filename}] #{status}"
end
if __FILE__ == $0
Credit.new.run()
end
end