- Ruby v2.1.5+
bundle install
Require the dependency.
require 'bc_ruby_api'
Setup your credentials:
BCAPIRuby::Requestor.credentials ({
sellerId: '208364',
privateKey: '2222',
sandbox: false
})
credit_card = {
number: '4111111111111111',
exp_month: 12,
exp_year: 2019,
cvv: '123'
}
address = {
name: 'Testing Tester',
address_1: '123 Test St',
address_2: 'the attic',
city: 'Columbus',
state: 'OH',
country_code: 'US',
postal_code: '43123'
}
payment_method = {
credit_card: credit_card,
address: address
}
customer = {
phone: '555-555-5556',
currency: 'USD',
lang: 'en',
email: '[email protected]',
payment_method: payment_method
}
test_sale = {
amount: 1.00,
merchant_order_id: '123',
customer: customer
}
sale = BCAPIRuby::Sale.create(test_sale)
puts sale.id #sale_id
puts sale.invoices[0].id #invoice_id
sale = BCAPIRuby::Sale.find(SALE_ID)
puts sale.id #sale_id
puts sale.invoices[0].id #invoice_id
pagination = {
page: 1,
page_size: 25
}
sale_list = BCAPIRuby::Sale.list(pagination)
puts sale_list.sales[0].id #sale_id
puts sale_list.pagenation.next #next page
invoice = BCAPIRuby::Invoice.find(INVOICE_ID)
puts invoice.id #invoiceID
pagination = {
page: 1,
page_size: 25
}
invoice_list = BCAPIRuby::Sale.list(pagination)
puts invoice_list.invoices[0] #first invoice
puts invoice_list.pagenation.next #next page
invoice = BCAPIRuby::Invoice.capture(INVOICE_ID)
puts invoice.id #invoiceID
puts invoice.needs_captured #false
params = {
amount: 1.00,
currency_type: 'vendor',
comment: 'Refund Issued'
}
invoice = BCAPIRuby::Invoice.refund(SALE_ID, params)
puts invoice.id #invoiceID
puts invoice.refunds[0].id #refundId
credit_card = {
number: '4111111111111111',
exp_month: 12,
exp_year: 2019,
cvv: '123'
}
address = {
name: 'Testing Tester',
address_1: '123 Test St',
address_2: 'the attic',
city: 'Columbus',
state: 'OH',
country_code: 'US',
postal_code: '43123'
}
payment_method = {
credit_card: credit_card,
address: address
}
test_customer = {
phone: '555-555-5556',
currency: 'USD',
lang: 'en',
email: '[email protected]',
payment_method: payment_method
}
customer = BCAPIRuby::Customer.create(test_customer)
puts customer.id #customerID
puts customer.payment_methods[0].id #paymentMethodId
customer = BCAPIRuby::Customer.find(CUSTOMER_ID)
puts customer.id #customerID
puts customer.payment_methods[0].id #paymentMethodId
pagination = {
page: 1,
page_size: 25
}
customer_list = BCAPIRuby::Sale.list(pagination)
puts customer_list.customers[0].id #first customer id
puts customer_list.pagenation.next #next page
customer = BCAPIRuby::Customer.update(CUSTOMER_ID, {email: '[email protected]'})
puts customer.id #customerId
puts customer.email #Updated email
deleted = BCAPIRuby::Customer.delete(CUSTOMER_ID)
puts customer.code #OK
credit_card = {
number: '4111111111111111',
exp_month: 12,
exp_year: 2019,
cvv: '123'
}
address = {
name: 'Testing Tester',
address_1: '123 Test St',
address_2: 'the attic',
city: 'Columbus',
state: 'OH',
country_code: 'US',
postal_code: '43123'
}
test_payment_method = {
credit_card: credit_card,
address: address
}
payment_method = BCAPIRuby::PaymentMethod.create(CUSTOMER_ID, test_payment_method)
puts payment_method.id #paymentMethodID
puts payment_method.brand #VS
payment_method = BCAPIRuby::PaymentMethod.find(CUSTOMER_ID, PAYMENT_METHOD_ID)
puts payment_method.id #paymentMethodID
puts payment_method.brand #VS
pagination = {
page: 1,
page_size: 25
}
payment_method_list = BCAPIRuby::Sale.list(pagination)
puts payment_method_list.payment_methods[0].id #first customer id
payment_method = BCAPIRuby::PaymentMethod.set_default(CUSTOMER_ID, PAYMENT_METHOD_ID)
puts payment_method.isDefault #true
deleted_payment_method = BCAPIRuby::PaymentMethod.delete($customer.id, method.id)
puts deleted_payment_method.code #OK
Subscriptions (recurring items) can be created when creating a sale by passing a recurrence and optionally a duration.
recurring_sale = {
amount: 1.00,
merchant_order_id: '123',
recurrence: '1 Month',
customer: CUSTOMER_ID
}
sale = BCAPIRuby::Sale.create(recurring_sale)
subscription = BCAPIRuby::Subscription.stop(sale.invoices[0].subscriptions[0].id)
puts subscription.id #subscriptionID
puts subscription.active #false
recurring_sale = {
amount: 1.00,
merchant_order_id: '123',
recurrence: '1 Month',
customer: CUSTOMER_ID
}
sale = BCAPIRuby::Sale.create(recurring_sale)
subscription = BCAPIRuby::Subscription.find(sale.invoices[0].subscriptions[0].id)
puts subscription.id #subscriptionID
puts subscription.active #true
Errors will be thrown if the request is not successful. You should always check the error object in your callback so that you can cleanly handle exceptions.
begin
sale = BCAPIRuby::Sale.create(test_sale)
puts sale.id
rescue => e
puts e.message
end
rspec