-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo_payment.rb
70 lines (51 loc) · 2.04 KB
/
demo_payment.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
#
# BlueVia is a global iniciative of Telefonica delivered by Movistar and O2.
# Please, check out www.bluevia.com and if you need more information
# contact us at mailto:support@bluevia.com
#
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
require 'bluevia'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
class DemoPayment
include Bluevia
begin
consumer_key= "xxxxxx"
consumer_secret= "yyyyyyy"
mode= BVMode::SANDBOX
# To create BVPayment client
@bc = BVPayment.new(mode, consumer_key, consumer_secret)
# A set of params
amount = "177"
currency="EUR"
service_name = "xxxxxxxxxx"
service_id = "xxxxxxxxxx"
callback = "oob"
# Oauth process special for payment API
pay_request_token = @bc.get_payment_request_token(amount, currency, service_name, service_id, callback)
puts "To get access token and secret, we need you to finish the payment authorization process following this url: "+ pay_request_token.auth_url
puts "Please, introduce the obtained pin code:"
STDOUT.flush
pin_code= gets.chomp
pay_access_token = @bc.get_payment_access_token(pin_code)
puts "Your access token and secret for the selected application are " + pay_access_token.token + " and "+ pay_access_token.secret
# To set payment tokens in the BVPayment Client
@bc.set_token(pay_access_token)
# Request for payment
answer = @bc.payment(amount, currency)
puts "Payment's answer: "
# Transaction information
puts answer.transaction_id
puts answer.transaction_status
puts answer.transaction_status_description
# In order to get information about the transaction do as follows.
ans2 = @bc.get_payment_status(answer.transaction_id)
p "Result from get_payment_status: "
p ans2.inspect
# To cancel payment authorization:
ans3 = @bc.cancel_authorization()
p "cancel_authorization returns: "
p ans3
rescue StandardError => e
puts "received Exception: #{e}"
end
end