Project

apruve

0.01
No commit activity in last 3 years
No release in over 3 years
Easily integrate the Apruve B2B payment network into your ruby-based application.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
~> 10.3

Runtime

>= 0.8.6, <= 0.9.0
 Project Readme

Apruve

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!

Installation

Add this line to your application's Gemfile:

gem 'apruve'

And then execute:

$ bundle

Or install it yourself as:

$ gem install apruve

Usage (merchant integration)

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

Create an account on Apruve.

Have a look though our Getting Started documentation and be sure to use test.apruve.com for test accounts.

Initialize the library

For test.apruve.com Apruve.configure('YOUR_APRUVE_API_KEY', 'test')

For app.apruve.com Apruve.configure('YOUR_APRUVE_API_KEY', 'prod')

Create an Order

@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'
  )

On your web page...

(example in ERB...)

At the top of the file, import the apruve.js script.

<%= Apruve.js %>

Write a little Javascript to configure apruve.js

  1. use setOrder to set the order JSON and secureHash string
  2. 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 %>

Back on your server...

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

Create a web hook listener

# 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

Contributing

  1. Fork it ( http://github.com/apruve/apruve_gem/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request