WePay Developer

Delayed payouts

Before reading this tutorial...

You should be familiar with the following concepts:

Delayed payouts allow marketplaces to charge customers immediately, but restrict access to the funds for a period of time. For example, you can charge a customer, but keep the funds unavailable to the seller until the item is delivered or the service is performed.

Delaying a payout occurs in two steps:

  1. Charge the customer with the auto_capture parameter set to false
  2. Release the funds with the /checkout/capture call

When to use conditional payments instead

If you're not sure whether you should charge the customer at all until some condition is met (like a "tipping point") you should use conditional payments, which allows you to get the customer's authorization to charge them at some point in the future.

Charge the customer

Delayed payouts are supported by the auto_capture parameter in the /checkout/create call. Simply set the auto_capture parameter to false when charging the customer, and the payment will remain in the reserved state until you say to release it.

API Call:

  • PHP
  • cURL
  • Ruby
  • Python
<?php
    // WePay PHP SDK - http://git.io/mY7iQQ
    require 'wepay.php';

    // application settings
    $account_id = 123456789;
    $client_id = 123456789;
    $client_secret = "1a3b5c7d9";
    $access_token = "1a3b5c7d9";

    // change to useProduction for live environments
    Wepay::useStaging($client_id, $client_secret);

    $wepay = new WePay($access_token);

    // create the checkout
    $response = $wepay->request('checkout/create', array(
        'account_id'        => $account_id,
        'amount'            => '24.95',
        'short_description' => 'A brand new soccer ball',
        'type'              => 'GOODS',
        'auto_capture'     => FALSE
    ));

    // display the response
    print_r($response);
?>
curl https://stage.wepayapi.com/v2/checkout/create \
	-H "Authorization: Bearer STAGE_8a19aff55b85a436dad5cd1386db1999437facb5914b494f4da5f206a56a5d20" \
	-d "account_id=123456789" \
	-d "amount=24.95" \
	-d "short_description=A brand new soccer ball" \
	-d "type=GOODS" \
	-d "auto_capture=FALSE"
				
# WePay Ruby SDK - http://git.io/a_c2uQ
require 'WePay_API_v2_Ruby_SDK.rb'

# application settings
account_id = 123456789
client_id = 123456789
client_secret = '1a3b5c7d9'
access_token = '1a3b5c7d9'

# set _use_stage to false for live environments
wepay = WePay.new(client_id, client_secret, _use_stage = true)

# create the checkout
response = wepay.call('/checkout/create', access_token, {
    :account_id         => account_id,
    :amount             => '24.95',
    :short_description  => 'A brand new soccer ball',
    :type               => 'GOODS',
    :auto_capture      => false
})

# display the response
p response
# WePay Python SDK - http://git.io/v7Y1jA
from wepay import WePay

# application settings
account_id = 123456789
access_token = '1a3b5c7d9'
production = False

# set production to True for live environments
wepay = WePay(production, access_token)
        
# create the checkout
response = wepay.call('/checkout/create', {
    'account_id': account_id,
    'amount': '24.95',
    'short_description': 'A brand new soccer ball',
    'type': 'GOODS',
    'auto_capture': False
})

# display the response
print response

Then complete the payment as you would any other payment (see charging customers for a refresher).

Release the funds

To release the money, make the /checkout/capture call with the appropriate access_token. If /checkout/capture is not called within 14 days, the payment will be canceled, and the cardholder will be refunded.

API Call:

Parameter Description
checkout_id The unique ID of the original payment (can found using /checkout/find)
  • PHP
  • cURL
  • Ruby
  • Python
<?php
    // WePay PHP SDK - http://git.io/mY7iQQ
    require 'wepay.php';

    // application settings
    $client_id = 123456789;
    $client_secret = "1a3b5c7d9";
    $access_token = "1a3b5c7d9";
    
    // change to useProduction for live environments
    Wepay::useStaging($client_id, $client_secret);

    $wepay = new WePay($access_token);

    // capture the checkout
    $response = $wepay->request('checkout/capture', array(
        'checkout_id' => 123456789
    ));

    // display the response
    print_r($response);
?>
curl https://stage.wepayapi.com/v2/checkout/capture \
	-H "Authorization: Bearer STAGE_8a19aff55b85a436dad5cd1386db1999437facb5914b494f4da5f206a56a5d20" \
	-d "checkout_id=123456789"
				
# WePay Ruby SDK - http://git.io/a_c2uQ
require 'WePay_API_v2_Ruby_SDK.rb'

# application settings
client_id = 123456789;
client_secret = '1a3b5c7d9';
access_token = '1a3b5c7d9';

# set _use_stage to false for live environments
wepay = WePay.new(client_id, client_secret, _use_stage = true)

# capture the checkout
response = wepay.call('/checkout/capture', access_token, {
    :checkout_id  => 123456789
})

# display the response
p response
# WePay Python SDK - http://git.io/v7Y1jA
from wepay import WePay

# application settings
access_token = '1a3b5c7d9'
production = False

# set production to True for live environments
wepay = WePay(production, access_token)
        
# capture the checkout
response = wepay.call('/checkout/capture', {
    'checkout_id': 123456789
})

# display the response
print response

You can also cancel the payment using the /checkout/cancel call.

What's
Next?