Apruve helps B2B merchants by helping manage complex business sales. The apruve gem makes it easier for merchants on Ruby-based platforms to integrate Apruve!
Add this line to your application's Gemfile:
gem 'apruve'
And then execute:
$ bundle
Or install it yourself as:
$ gem install apruve
The following snippets are based on our apruve-ruby-demo project, which is a functional demo of how a merchant can integrate Apruve.
https://github.com/apruve/apruve-ruby-demo
Have a look though our Getting Started documentation and be sure to use test.apruve.com for test accounts.
For test.apruve.com Apruve.configure('YOUR_APRUVE_API_KEY', 'test')
For app.apruve.com Apruve.configure('YOUR_APRUVE_API_KEY', 'prod')
@order = Apruve::Order.new(
merchant_id: your_merchant_id,
currency: 'USD',
amount_cents: 6000,
shipping_cents: 500
)
@order.order_items << Apruve::OrderItem.new(
title: 'Letter Paper',
description: '20 lb ream (500 Sheets). Paper dimensions are 8.5 x 11.00 inches.',
sku: 'LTR-20R',
price_ea_cents: 1200,
quantity: 3,
price_total_cents: 3600,
view_product_url: 'https://www.example.com/letter-paper'
)
(example in ERB...)
At the top of the file, import the apruve.js script.
<%= Apruve.js %>
Write a little Javascript to configure apruve.js
- use setOrder to set the order JSON and secureHash string
- register a callback to capture orderId
apruve.setOrder(<%= @order.to_json %>, '<%= @order.secure_hash %>');
apruve.registerApruveCallback(apruve.APRUVE_COMPLETE_EVENT, function (orderId) {
$('#orderId').val(orderId)
$('#finishOrder').submit();
});
Decide where to put the Apruve button
<%= Apruve.button %>
Use the orderId to issue an Invoice
apruve_invoice = Apruve::Invoice.new(order_id: params[:order_id], amount_cents: params[:charge], issue_on_create: true)
apruve_invoice.save!
Save the status and the invoice ID with the payment in your database
# dependent on your system, but something like this...
my_invoice.apruve_invoice_id = apruve_invoice.id
my_invoice.apruve_invoice_status = apruve_payment.status
my_invoice.save!
(optional) If you track orders separately from payments, save the orderId with your order in your database
# dependent on your system, but something like this...
my_order.apruve_order_id = params[:order_id]
my_order.save
# dependent on your system, but if you use Sinatra, it might look something like this...
post '/webhook_notify' do
# We got a webhook. You should look up the order in your database and complete or cancel it as appropriate.
puts "GOT WEBHOOK DATA FOR INVOICE #{@webhook_data}"
my_invoice.find_by(apruve_invoice_id: @webhook_data[:invoice_id])
my_invoice.apruve_payment_status = @webhook_data[:status]
if my_invoice.apruve_invoice_status == 'closed'
my_invoice.complete_order
elsif my_invoice.apruve_invoice_status == 'canceled'
my_invoice.cancel_order
end
end
- Fork it ( http://github.com/apruve/apruve_gem/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request