Daikini

We're human after all.

PaySimple Plugin/Gem

Posted by Jonathan on June 29, 2007 at 12:09 PM

For RoundHaus I needed to find a payment processor for collecting subscription payments and after doing a fair bit of research I found PaySimple. I was very impressed with their service and support. It is absolutely top notch and I highly recommend them.

There wasn’t anything out there in Rubyland for dealing with PaySimple though so I created the PaySimple plugin/gem. The library provides a simple interface to find, create, edit, delete, and query subscriptions using the PaySimple SOAP API.

Installation:

The simple way:

$ sudo gem install paysimple

Directly from repository:

$ svn co svn://svn.roundhaus.com/daikini/plugins/paysimple

Requirements:

  • soap4r 1.5.6 or higher

Configuration:

When you signup for a PaySimple account you can setup a source key and optionally a pin and client ip address. These are your credentials when using the PaySimple API.

   1  PaySimple.key = "123456"
   2  PaySimple.pin = "topsecret"
   3  PaySimple.client_ip = "192.168.0.1"

Usage:

   1  require 'rubygems'
   2  require 'paysimple'
   3  
   4  # Bill Jennifer $12.00 monthly
   5  begin
   6    customer_number = PaySimple::Subscription.create(
   7      :CustomerID => 12345,
   8      :BillingAddress => {
   9        :FirstName => "Jennifer",
  10        :LastName => "Smith"
  11      },
  12      :CreditCardData => {
  13        :CardNumber => '4444555566667779',
  14        :CardExpiration => '0908'
  15      },
  16      :Schedule => :monthly,
  17      :Next => "2008-09-05",
  18      :Amount => 12.00
  19    )
  20  
  21    puts "Subscription created with Customer Number: #{customer_number}"
  22  rescue Exception => e
  23    puts "An error occurred: #{e.message}"
  24  end
  25  
  26  
  27  # Update subscription to use new credit card
  28  begin
  29    customer_number = 12345
  30    response = PaySimple::Subscription.update(
  31      customer_number,
  32      :CreditCardData => {
  33        :CardNumber => '4444555566667779',
  34        :CardExpiration => '0908'
  35      }
  36    )
  37  
  38    puts "Subscription updated"
  39  rescue Exception => e
  40    puts "An error occurred: #{e.message}"
  41  end
  42  
  43  
  44  # Delete subscription
  45  begin
  46    customer_number = 12345
  47    response = PaySimple::Subscription.delete(customer_number)
  48  
  49    puts "Subscription removed from active use."
  50  rescue Exception => e
  51    puts "An error occurred: #{e.message}"
  52  end
  53  
  54  
  55  # Find an existing subscription
  56  begin
  57    customer_number = 12345
  58    customer = PaySimple::Subscription.find(customer_number)
  59  
  60    puts "Found subscription for #{ [customer["BillingAddress"]["FirstName"], customer["BillingAddress"]["LastName"]].join(" ")}"
  61  rescue Exception => e
  62    puts "An error occurred: #{e.message}"
  63  end
  64  
  65  
  66  # Process one-time sale against existing subscription
  67  begin
  68    customer_number = 12345
  69    response = PaySimple::Subscription.charge(customer_number, :Amount => 34.56)
  70  
  71    if response['Response'] == "Approved"
  72      puts "One-time charge successful."
  73    else
  74      puts "An error occurred: #{response['Error']}"
  75    end
  76  rescue Exception => e
  77    puts "An error occurred: #{e.message}"
  78  end
  79  
  80  
  81  # Search for transactions
  82  begin
  83    response = PaySimple::Subscription.query(
  84      [ 
  85        { :Field => 'amount', :Type => 'gt', :Value => '5.0' }
  86      ]
  87    )
  88  
  89    response.transactions.each do |transaction|
  90      puts "CustomerID = #{transaction['CustomerID']}, Amount = #{transaction['Details']['Amount']}"
  91    end
  92  rescue Exception => e
  93    puts "An error occurred: #{e.message}"
  94  end

LICENSE:

paysimple is licensed under the MIT License.

Copyright (c) 2007 [Jonathan Younger], released under the MIT license

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Tags: plugin, rails
Hierarchy: previous, next

Comments

There are 0 comments on this post. Post yours →

Post a comment

Required fields in bold.