Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pkg/
Gemfile.lock
*.gem
.project
.idea
.bundle
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "examples/marketplace/fe"]
path = examples/marketplace/fe
url = git@github.com:PoundPay/simplefe.git
133 changes: 128 additions & 5 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Poundpay is a payments platform for marketplaces

1. Add the following to your Gemfile

gem 'poundpay', '~> 0.2.0'
gem 'poundpay', '~> 0.3.1'

2. At the command prompt, install the gem with bundler

Expand Down Expand Up @@ -35,6 +35,13 @@ Poundpay is a payments platform for marketplaces

before_filter :verify_poundpay_callback

== Creating a user

@user = Poundpay::User.create(
:first_name => "Dart",
:last_name => "Master",
:email_address => "dart-master@example.com")


== Creating a payment

Expand All @@ -47,7 +54,7 @@ Poundpay is a payments platform for marketplaces
:description => "Beats by Dr. Dre")


== Serving IFRAME
== Serving the payment IFRAME

<script src="https://www.poundpay.com/js/poundpay.js"></script>

Expand Down Expand Up @@ -79,6 +86,122 @@ Poundpay is a payments platform for marketplaces
== Payment methods

payment = Poundpay::Payment.find(payment_sid)
payment.escrow # AUTHORIZED -> ESCROWED. Credit card is charged
payment.release # ESCROWED -> RELEASED. Recipient receives money
payment.cancel # ESCROWED -> CANCELED. Payer receives refund
payment.escrow # AUTHORIZED -> ESCROWED. Credit card is charged
payment.release # ESCROWED or PARTIALLY_RELEASED -> RELEASED. Recipient receives money
payment.cancel # ESCROWED or PARTIALLY_RELEASED -> CANCELED. Payer receives refund
Poundpay::Payment.batch_update # Batch update a list of payments.


== Creating a charge permission

@charge_permission = Poundpay::ChargePermission.create(
:email_address => "fred@example.com")


== Serving the charge permission IFRAME

<script src="https://www.poundpay.com/js/poundpay.js"></script>

<div id="pound-root"></div>

<script>
function handleChargePermissionSuccess() {
// do something
}

function handleChargePermissionError() {
// handle error
}

PoundPay.init({
charge_permission_sid: "<%= @charge_permission.sid %>",
success: handleChargePermissionSuccess,
error: handleChargePermissionError,
name: "Fred Nietzsche", // Optional
address_street: "330 Townsend St", // Optional
address_city: "San Francisco", // Optional
address_state: "California", // Optional
address_zip: "94107", // Optional
server: "<%= Poundpay.www_url %>"
});
</script>


== Charge permission methods

charge_permission = Poundpay::ChargePermission.find(charge_permission_sid)
charge_permission.deactivate # CREATED or ACTIVE -> INACTIVE. Charge permission is deactivated and can no longer be used to authorize payments for the associated payer.


== Batching

In some cases you may wish to batch authorize and escrow a collection of
payments. By doing so there will be only *one* payer charge for that collection
of payments. Note that if you do batch authorize a collection of payments that
it must *also* be batch escrowed.

Batching is designed for shopping carts where you want a collection of payments
to appear to appear as a single charge.

In order to use batching you simply need to pass `sids` for *all* payments in
the collection you want to batch to the IFrame

<script src="https://www.poundpay.com/js/poundpay.js"></script>

<div id="pound-root"></div>

<script>
function handlePaymentSuccess() {
// do something
}

function handlePaymentError() {
// handle error
}

PoundPay.init({
payment_sid: [
"<%= @payment1.sid %>"
"<%= @payment2.sid %>",
"<%= @payment3.sid %>"
],
success: handlePaymentSuccess,
error: handlePaymentError,
first_name: "Fred", // Optional
last_name: "Nietzsche", // Optional
address_street: "990 Guerrero St", // Optional
address_city: "San Francisco", // Optional
address_state: "California", // Optional
address_zip: "94110", // Optional
server: "https://www-sandbox.poundpay.com" // Exclude for production
});
</script>

Alternatively if you are directly authorizing the payments using a charge
permission

Poundpay::Payment.batch_update(
:sid => [payment1.sid, payment2.sid, payment3.sid],
:status => 'AUTHORIZED')

Finally you'll need to batch escrow the payments

Poundpay::Payment.batch_update(
:sid => [payment1.sid, payment2.sid, payment3.sid],
:status => 'ESCROWED')

Notice that if you did the following instead an error would be triggered since
batched payments *must* be authorized and escrowed collectively

payment = Poundpay::Payment.find(payment1_sid)
payment.escrow # fails

However if you cancel some of the payments prior to batch escrow you should
exclude them from the batch call

payment1 = Poundpay::Payment.find(payment1_sid)
payment1.cancel # ok

Poundpay::Payment.batch_update(
:sid => [payment2.sid, payment3.sid],
:status => 'ESCROWED')
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# echo 'Switching rvm gemset ...'
rvm use --create --install 1.9.1@poundpay-simple_application >& /dev/null
rvm use --create --install 1.9.2@poundpay-simple_application >& /dev/null
# rvm gemset import >& /dev/null
File renamed without changes.
181 changes: 181 additions & 0 deletions examples/marketplace/application.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
require 'pp'
require 'poundpay'

require './config'


class SimpleController
attr_reader :poundpay_client

def initialize
if Poundpay.configured?
return
end
config = SimpleApplication::CONFIG[:poundpay]
puts config
Poundpay.configure_from_hash(config)
end

def return_404
response = Rack::Response.new(["Page Not Found"], 404, {"Content-Type" => "text/plain"})
response.finish
end

end

class Index < SimpleController

def call env
request = Rack::Request.new(env)
unless request.path == '/' and request.get?
return return_404
end
# Create payment request
payment = SimpleApplication::CONFIG[:default_payment]
# Render and return page
www_poundpay_url = Poundpay.www_url
template = ERB.new(open("index.html.erb").read)
page = template.result(binding)
response = Rack::Response.new([page], 200, {"Content-Type" => "text/html"})
response.finish
end

end

class Payment < SimpleController

def call env
request = Rack::Request.new(env)
return_value, mime_type = case request.path.gsub(/\/$/, '') # trim trailing /
when '/payment' then request.post? ? create(request) : [nil, nil]
when '/payment/release' then request.post? ? release(request) : [nil, nil]
when '/payment/authorize' then request.post? ? authorize(request) : [nil, nil]
when '/payment/cancel' then request.post? ? cancel(request) : [nil, nil]
when '/payment/escrow' then request.post? ? escrow(request) : [nil, nil]
else nil
end

if return_value
response = Rack::Response.new([return_value], 201, {"Content-Type" => mime_type})
response.finish
else
return_404
end
end

def create request
payment = Poundpay::Payment.create(request.POST)
payment.include_root_in_json = false
return payment.to_json(), "application/json"
end

def authorize request
if request.POST['sid'].kind_of?(Array)
payments = Poundpay::Payment.batch_update(:sid => request.POST['sid'], :state => 'authorized')
payments = payments.collect! {|p| p.schema }
return PP.pp(payments, ''), "text/html"
else
payment = Poundpay::Payment.find(request.POST['sid'])
payment.authorize
payment.save
return PP.pp(payment.schema, ''), "text/html"
end
end

def release request
payment = Poundpay::Payment.find(request.POST['sid'])
payment.release
return PP.pp(payment.schema, ''), "text/html"
end

def cancel request
payment = Poundpay::Payment.find(request.POST['sid'])
payment.cancel
return PP.pp(payment.schema, ''), "text/html"
end

def escrow request
if request.POST['sid'].kind_of?(Array)
payments = Poundpay::Payment.batch_update(:sid => request.POST['sid'], :state => 'escrowed')
payments = payments.collect! {|p| p.schema }
return PP.pp(payments, ''), "text/html"
else
payment = Poundpay::Payment.find(request.POST['sid'])
payment.escrow
return PP.pp(payment.schema, ''), "text/html"
end
end

end


class User < SimpleController

def call env
request = Rack::Request.new(env)
return_value, mime_type = case request.path.gsub(/\/$/, '') # trim trailing /
when '/user' then request.post? ? create(request) : [nil, nil]
else [nil, nil]
end

if return_value
response = Rack::Response.new([return_value], 201, {"Content-Type" => mime_type})
response.finish
else
return_404
end
end

def create request
user = Poundpay::User.create({
:first_name => request.POST['user_first_name'],
:last_name => request.POST['user_last_name'],
:email_address => request.POST['user_email_address']
})
return PP.pp(user.schema, ''), "text/html"
end

end


class ChargePermission < SimpleController

def call env
request = Rack::Request.new(env)
return_value, mime_type = case request.path.gsub(/\/$/, '') # trim trailing /
when '/charge_permission' then request.post? ? create(request) : [nil, nil]
when '/charge_permission/find' then request.post? ? show(request) : [nil, nil]
when '/charge_permission/deactivate' then request.post? ? deactivate(request) : [nil, nil]
else [nil, nil]
end

if return_value
response = Rack::Response.new([return_value], 201, {"Content-Type" => mime_type})
response.finish
else
return_404
end
end

def create request
charge_permission = Poundpay::ChargePermission.create(request.POST)
charge_permission.include_root_in_json = false
return charge_permission.to_json(), "application/json"
end

def show request
charge_permissions = Poundpay::ChargePermission.find(:all, :params => { :email_address => request.POST['email_address'] })
if charge_permissions
return PP.pp(charge_permissions.map {|cp| cp.schema}, ''), 'text/plain'
else
return [nil, nil]
end
end

def deactivate request
charge_permission = Poundpay::ChargePermission.find(request.POST['sid'])
charge_permission.deactivate
return PP.pp(charge_permission.schema, ''), 'text/plain'
end

end
20 changes: 20 additions & 0 deletions examples/marketplace/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class SimpleApplication
CONFIG = {
poundpay: {
"api_url" => "https://api-sandbox.poundpay.com",
"www_url" => "https://www-sandbox.poundpay.com",
"version" => "silver",
"developer_sid" => "DVxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"auth_token" => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"callback_url" => '',
},
default_payment: {
"amount" => "67890",
"payer_fee_amount" => "100",
"recipient_fee_amount" => "200",
"payer_email_address" => "sam@example.com",
"recipient_email_address" => "jacob@example.net",
"description" => "this is a simple description that just loves developers, developers",
}
}
end
Loading