Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
71 lines (51 sloc) 2.04 KB
# BlueVia is a global iniciative of Telefonica delivered by Movistar and O2.
# Please, check out and if you need more information
# contact us at
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
require 'bluevia'
class DemoPayment
include Bluevia
consumer_key= "xxxxxx"
consumer_secret= "yyyyyyy"
mode= BVMode::SANDBOX
# To create BVPayment client
@bc =, consumer_key, consumer_secret)
# A set of params
amount = "177"
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:"
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
# 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}"