-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbraintree_test.rb
81 lines (69 loc) · 2.08 KB
/
braintree_test.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
require "rubygems"
require "braintree"
Braintree::Configuration.environment = :sandbox
Braintree::Configuration.merchant_id = "wj6wnxrgdvh5v5rx"
Braintree::Configuration.public_key = "cdcsdmnwsfdtmf2j"
Braintree::Configuration.private_key = "6k4b8m868p44dqpt"
result = Braintree::Customer.create(
:first_name => "Charity",
:last_name => "Smith",
:credit_card => {
:number => "5105105105105100",
:expiration_date => "05/2010",
:options => {
:verify_card => true
}
}
)
if result.success?
puts result.customer.id
puts result.customer.credit_cards[0].token
else
p result.errors
end
result = Braintree::Subscription.create(
:payment_method_token => "jvwx",
:plan_id => "GOLD_LEVEL"
)
if result.success?
puts result.subscription.id
puts result.subscription.transactions[0].id
end
result = Braintree::CreditCard.sale("jvwx", :amount => "10.00")
if result.success?
puts "Transaction ID: #{result.transaction.id}"
# status will be authorized or submitted_for_settlement
puts "Transaction Status: #{result.transaction.status}"
else
puts "Message: #{result.message}"
if result.transaction.nil?
# validation errors prevented transaction from being created
p result.errors
else
puts "Transaction ID: #{result.transaction.id}"
# status will be processor_declined, gateway_rejected, or failed
puts "Transaction Status: #{result.transaction.status}"
end
end
result = Braintree::Transaction.sale(
:amount => "1000.00",
:credit_card => {
:number => "5105105105105100",
:expiration_date => "05/12"
}
)
if result.success?
puts "Transaction ID: #{result.transaction.id}"
# status will be authorized or submitted_for_settlement
puts "Transaction Status: #{result.transaction.status}"
else
puts "Message: #{result.message}"
if result.transaction.nil?
# validation errors prevented transaction from being created
p result.errors
else
puts "Transaction ID: #{result.transaction.id}"
# status will be processor_declined, gateway_rejected, or failed
puts "Transaction Status: #{result.transaction.status}"
end
end