Sha256: 57baec946108a8f826638be4267bb8b34138247408148d92896d88a56b1ca798

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

cwd = File.dirname(File.dirname(File.expand_path(__FILE__)))
$:.unshift(cwd + "/lib")
require 'rubygems'
require 'balanced'

begin
  Balanced::Card
rescue NameError
  raise "wtf"
end

require 'balanced'

Balanced.configure("8bb66df4e80711e290df026ba7cd33d0")

puts "create our marketplace"
begin
  marketplace = Balanced::Marketplace.new.save
rescue Balanced::Conflict => ex
  # balanced automatically maps the body's response
  # for convenience, so for example:
  puts ex.response[:body]
  # you'll notice this hash is mapped to nice attributes
  raise "Not Present" if ex.response[:body]["status"] != ex.status
  # you can find all of the attributes here:
  # https://docs.balancedpayments.com/current/api?language=bash#errors
  marketplace = Balanced::Marketplace.mine
end

# create a new card

card = Balanced::Card.new(
  :card_number => "5105105105105100",
  :expiration_month => "12",
  :expiration_year => "2015",
  :phone_number => "INCORRECT PHONE NUMBER"
)

begin
  card.save
rescue Balanced::BadRequest => ex
  puts ex.extras[:phone_number]
  puts "All the fields that have errors are: #{ex.extras.keys}"
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
balanced-0.8.2 examples/exception_handling.rb
balanced-0.8.1 examples/exception_handling.rb