Note: The api only responds to the models which are included with the php package.
- Installation
- Configuration
- Examples
- Async and Wrappers
- Contributing
You can include this package via Composer.
{
"require": {
"promisepay/promisepay-php": "2.*"
}
}
Install the package.
composer install
Require the package in the controller where you'll be using it.
use PromisePay\PromisePay;
Download the latest release from GitHub, then require the package in the relevant controller.
use PromisePay\PromisePay;
Before interacting with PromisePay API, you'll need to create a prelive account and get an API token.
Afterwards, you need to declare environment, login (your email address) and password (API token), thus:
PromisePay::Configuration()->environment('prelive'); // Use 'production' for the production environment.
PromisePay::Configuration()->login('your_email_address');
PromisePay::Configuration()->password('your_token');
The below example shows the request for a marketplace configured to have the Item and User IDs generated automatically for them.
$token = PromisePay::Token()->requestSessionToken(array(
'current_user' => 'seller',
'item_name' => 'Test Item',
'amount' => '2500',
'seller_lastname' => 'Seller',
'seller_firstname' => 'Sally',
'buyer_lastname' => 'Buyer',
'buyer_firstname' => 'Bobby',
'buyer_country' => 'AUS',
'seller_country' => 'USA',
'seller_email' => 'sally.seller@promisepay.com',
'buyer_email' => 'bobby.buyer@promisepay.com',
'fee_ids' => '',
'payment_type_id' => '2'
));
$item = PromisePay::Item()->create(array(
"id" => 'ITEM_ID',
"name" => 'Test Item #1',
"amount" => 1000,
"payment_type_id" => 1,
"buyer_id" => 'BUYER_ID',
"seller_id" => 'SELLER_ID',
"description" => 'Description'
));
$item = PromisePay::Item()->get('ITEM_ID');
$items = PromisePay::Item()->getList(array(
'limit' => 20,
'offset' => 0
));
$item = PromisePay::Item()->update('ITEM_ID', array(
"id" => 'ITEM_ID',
"name" => 'Test Item #1',
"amount" => 1000,
"payment_type_id" => 1,
"buyer_id" => 'BUYER_ID',
"seller_id" => 'SELLER_ID',
"description" => 'Description'
));
$item = PromisePay::Item()->delete('ITEM_ID');
$item = PromisePay::Item()->getStatus('ITEM_ID');
$user = PromisePay::Item()->getBuyer('ITEM_ID');
$user = PromisePay::Item()->getSeller('ITEM_ID');
$fees = PromisePay::Item()->getListOfFees('ITEM_ID');
$transactions = PromisePay::Item()->getListOfTransactions('ITEM_ID');
$wireDetails = PromisePay::Item()->getWireDetails('ITEM_ID');
$bPayDetails = PromisePay::Item()->getBPayDetails('ITEM_ID');
$item = PromisePay::Item()->makePayment('ITEM_ID', array(
'account_id' => 'BUYER_ACCOUNT_ID'
));
$item = PromisePay::Item()->requestPayment('ITEM_ID');
$item = PromisePay::Item()->releasePayment('ITEM_ID');
$item = PromisePay::Item()->requestRelease('ITEM_ID');
$item = PromisePay::Item()->cancelItem('ITEM_ID');
$item = PromisePay::Item()->acknowledgeWire('ITEM_ID');
$item = PromisePay::Item()->acknowledgePayPal('ITEM_ID');
$item = PromisePay::Item()->revertWire('ITEM_ID');
$item = PromisePay::Item()->requestRefund('ITEM_ID', array(
'refund_amount' => 1000,
'refund_message' => 'Frame already constructed.'
));
$item = PromisePay::Item()->refund('ITEM_ID', array(
'refund_amount' => 1000,
'refund_message' => 'Stable deck refund.'
));
$declineRefund = PromisePay::Item()->declineRefund(
'ITEM_ID'
);
$raiseDispute = PromisePay::Item()->raiseDispute(
'ITEM_ID',
'BUYER_ID'
);
$requestDisputeResolution = PromisePay::Item()->requestDisputeResolution(
'ITEM_ID'
);
$resolveDispute = PromisePay::Item()->resolveDispute(
'ITEM_ID'
);
$resolveDispute = PromisePay::Item()->escalateDispute(
'ITEM_ID'
);
$requestTaxInvoice = PromisePay::Item()->requestTaxInvoice(
'ITEM_ID'
);
$batchTransactions = PromisePay::Item()->listBatchTransactions('ITEM_ID');
$sendTaxInvoice = PromisePay::Item()->sendTaxInvoice(
'ITEM_ID'
);
$user = PromisePay::User()->create(array(
'id' => 'USER_ID',
'first_name' => 'UserCreateTest',
'last_name' => 'UserLastname',
'email' => 'email@google.com',
'mobile' => '5455400012',
'address_line1' => 'a_line1',
'address_line2' => 'a_line2',
'state' => 'state',
'city' => 'city',
'zip' => '90210',
'country' => 'AUS'
));
$user = PromisePay::User()->get('USER_ID');
$users = PromisePay::User()->getList(array(
'limit' => 20,
'offset' => 0
));
$user = PromisePay::User()->update('USER_ID', array(
'id' => 'USER_ID',
'first_name' => 'UserCreateTest',
'last_name' => 'UserLastname',
'email' => 'email@google.com',
'mobile' => '5455400012',
'address_line1' => 'a_line1',
'address_line2' => 'a_line2',
'state' => 'state',
'city' => 'city',
'zip' => '90210',
'country' => 'AUS'
));
$accounts = PromisePay::User()->getListOfCardAccounts('USER_ID');
$accounts = PromisePay::User()->getListOfPayPalAccounts('USER_ID');
$accounts = PromisePay::User()->getListOfBankAccounts('USER_ID');
$items = PromisePay::User()->getListOfItems('USER_ID');
$accounts = PromisePay::User()->getListOfWalletAccounts('USER_ID');
$account = PromisePay::User()->setDisbursementAccount('USER_ID', array(
'account_id' => 'ACCOUNT_ID'
));
$wallet = PromisePay::WalletAccounts()->show('WALLET_ID');
// Withdraw to PayPal
// Authorize bank account to be used as a funding source
$authority = PromisePay::DirectDebitAuthority()->create(
array(
'account_id' => 'SOURCE_BANK_ID',
'amount' => 100
)
);
$withdrawal = PromisePay::WalletAccounts()->withdraw(
'SOURCE_BANK_ID',
array(
'account_id' => 'PAYPAY_ACCOUNT_ID',
'amount' => 100
)
);
// Withdraw to Bank Account
// Authorize bank account to be used as a funding source
$authority = PromisePay::DirectDebitAuthority()->create(
array(
'account_id' => 'SOURCE_BANK_ID',
'amount' => 100
)
);
$withdrawal = PromisePay::WalletAccounts()->withdraw(
'SOURCE_BANK_ID',
array(
'account_id' => 'TARGET_BANK_ID',
'amount' => 100
)
);
// Authorize bank account to be used as a funding source
$authority = PromisePay::DirectDebitAuthority()->create(
array(
'account_id' => 'SOURCE_BANK_ID',
'amount' => 100
)
);
$deposit = PromisePay::WalletAccounts()->deposit(
'TARGET_WALLET_ID',
array(
'account_id' => 'SOURCE_BANK_ID',
'amount' => 100
)
);
$walletUser = PromisePay::WalletAccounts()->getUser('WALLET_ID');
$account = PromisePay::CardAccount()->create(array(
'user_id' => 'USER_ID',
'full_name' => 'Bobby Buyer',
'number' => '4111111111111111',
"expiry_month" => '06',
"expiry_year" => '2020',
"cvv" => '123'
));
$account = PromisePay::CardAccount()->get('CARD_ACCOUNT_ID');
$account = PromisePay::CardAccount()->delete('CARD_ACCOUNT_ID');
$user = PromisePay::CardAccount()->getUser('CARD_ACCOUNT_ID');
$account = PromisePay::BankAccount()->create(array(
"user_id" => 'USER_ID',
"active" => 'true',
"bank_name" => 'bank for test',
"account_name" => 'test acc',
"routing_number" => '12344455512',
"account_number" => '123334242134',
"account_type" => 'savings',
"holder_type" => 'personal',
"country" => 'USA',
));
$account = PromisePay::BankAccount()->get('BANK_ACCOUNT_ID');
$account = PromisePay::BankAccount()->delete('BANK_ACCOUNT_ID');
$user = PromisePay::BankAccount()->getUser('BANK_ACCOUNT_ID');
$validateRoutingNumber = PromisePay::BankAccount()->validateRoutingNumber(
'ROUTING_NUMBER'
);
$account = PromisePay::PayPalAccount()->create(array(
'user_id' => 'USER_ID',
'paypal_email' => 'test@paypalname.com'
));
$account = PromisePay::PayPalAccount()->get('PAYPAL_ACCOUNT_ID');
$account = PromisePay::PayPalAccount()->delete('PAYPAL_ACCOUNT_ID');
$user = PromisePay::PayPalAccount()->getUser('PAYPAL_ACCOUNT_ID');
$batches = PromisePay::BatchTransactions()->listTransactions();
$batch = PromisePay::BatchTransactions()->showTransaction(
'BATCH_TRANSACTION_ID'
);
$createCharge = PromisePay::Charges()->create(
array
(
'account_id' => 'CARD_OR_BANK_ACCOUNT_ID',
'amount' => 100,
'email' => 'charged.user@email.com',
'zip' => 90210,
'country' => 'AUS',
'device_id' => 'DEVICE_ID',
'ip_address' => '49.229.186.182'
)
);
$getList = PromisePay::Charges()->getList();
$charge = PromisePay::Charges()->show('CHARGE_ID');
$buyer = PromisePay::Charges()->showBuyer('CHARGE_ID');
$status = PromisePay::Charges()->showStatus('CHARGE_ID');
$marketplaces = PromisePay::Marketplaces()->show();
$cardToken = PromisePay::Token()->generateCardToken(
array
(
'token_type' => 'card',
'user_id' => 'USER_ID'
)
);
$directDebitAuthority = PromisePay::DirectDebitAuthority()->create(
array
(
'account_id' => 'ACCOUNT_ID',
'amount' => 100
)
);
$getList = PromisePay::DirectDebitAuthority()->getList(
array
(
'account_id' => 'BANK_ACCOUNT_ID'
)
);
$directDebitAuthority = PromisePay::DirectDebitAuthority()->show(
'DIRECT_DEBIT_AUTHORITY_ID'
);
$deleteDirectDebitAuthority = PromisePay::DirectDebitAuthority()->delete(
'DIRECT_DEBIT_AUTHORITY_ID'
);
$company = PromisePay::Company()->create(array(
'user_id' => 'USER_ID',
'legal_name' => 'Test edit company',
'name' => 'test company name edit',
'country' => 'AUS'
));
$company = PromisePay::Company()->get('COMPANY_ID');
$companys = PromisePay::Company()->getList(array(
'limit' => 20,
'offset' => 0
));
$company = PromisePay::Company()->update('COMPANY_ID', array(
'id' => "e466dfb4-f05c-4c7f-92a3-09a0a28c7af5",
'user_id' => "1",
'name' => "Acme Co",
'legal_name' => "Acme Co Pty Ltd",
'tax_number' => "1231231",
'charge_tax' => true,
'address_line1' => "123 Test St",
'address_line2' => "",
'city' => "Melbourne",
'state' => "VIC",
'zip' => "3000",
'country' => "AUS"
));
$fees = PromisePay::Fee()->getList(array(
'limit' => 20,
'offset' => 0
));
$fee = PromisePay::Fee()->get('FEE_ID');
$fee = PromisePay::Fee()->create(array(
'amount' => 1000,
'name' => 'fee test',
'fee_type_id' => '1',
'cap' => '1',
'max' => '3',
'min' => '2',
'to' => 'buyer'
));
$transactions = PromisePay::Transaction()->getList(array(
'limit' => 20,
'offset' => 0
));
$transaction = PromisePay::Transaction()->get('TRANSACTION_ID');
$user = PromisePay::Transaction()->getUser('TRANSACTION_ID');
$fee = PromisePay::Transaction()->getFee('TRANSACTION_ID');
$walletAccount = PromisePay::Transaction()->getWalletAccount(
'TRANSACTION_ID'
);
$cardAccount = PromisePay::Transaction()->getCardAccount(
'TRANSACTION_ID'
);
$address = PromisePay::Address()->get('ADDRESS_ID');
$healthStatus = PromisePay::Tools()->getHealth();
$configuration = PromisePay::Configurations()->create(array(
'name' => 'partial_refunds',
'enabled' => true
));
$configuration = PromisePay::Configurations()->get('CONFIGURATION_ID');
$configurations = PromisePay::Configurations()->getList();
$configuration = PromisePay::Configurations()->update(array(
'id' => 'CONFIGURATION_ID',
'max' => 12345,
'name' => 'partial_refunds',
'enabled' => true
));
PromisePay::Configurations()->delete('CONFIGURATION_ID');
$list = PromisePay::PaymentRestrictions()->getList();
$paymentRestriction = PromisePay::PaymentRestrictions()->get('PAYMENT_RESTRICTION_ID');
$callback = PromisePay::Callbacks()->create(array(
'description' => 'Users Callback',
'url' => 'https://domain.tld/your/post/endpoint',
'object_type' => 'users',
'enabled' => true
));
$getList = PromisePay::Callbacks()->getList();
$getCallback = PromisePay::Callbacks()->get('f92d4ca1-4ee5-43f3-9e34-ca5f759c5e76');
$update = PromisePay::Callbacks()->update('f92d4ca1-4ee5-43f3-9e34-ca5f759c5e76', array(
'description' => 'Users Callback',
'url' => 'https://domain.tld/your/post/endpoint',
'object_type' => 'users',
'enabled' => false
));
$delete = PromisePay::Callbacks()->delete('f92d4ca1-4ee5-43f3-9e34-ca5f759c5e76');
$callbackResponsesList = PromisePay::Callbacks()->getListResponses('f92d4ca1-4ee5-43f3-9e34-ca5f759c5e76');
$callbackResponse = PromisePay::Callbacks()->getResponse(
'f92d4ca1-4ee5-43f3-9e34-ca5f759c5e76', // callback ID
'4476b384-fa48-4473-98ec-8fcdda4a1e84' // response ID
);
Asynchronous execution provides a significant speed improvement, as compared to synchronous execution.
PromisePay::AsyncClient(
function() {
PromisePay::Token()->generateCardToken('CARD_TOKEN_ID');
},
function() {
PromisePay::Transaction()->get('TRANSACTION_ID');
},
function() {
PromisePay::Transaction()->getUser('USER_ID');
},
function() {
PromisePay::BatchTransactions()->listTransactions();
}
)->done(
$cardToken,
$transaction,
$transactionUser,
$batchTransactions
);
Response variables are placed inside done()
method; they can be used both as arrays and objects, but using them as objects provides finer grained control. For example, the following will return equivalent data: $cardToken['user_id']
and $cardToken->getJson('user_id')
.
Response variables contain the following methods/getters:
getJson()
-> full response JSONgetMeta()
-> meta array extracted from response JSON, if presentgetLinks()
-> links array extracted from response JSON, if presentgetDebug()
-> response headers
Two wrappers are available: PromisePay::getAllResults()
and PromisePay::getAllResultsAsync()
. They can be used to get all results from sets of result pages, instead of up to 200 per request. For example, they can be used to fetch all batch transactions at once. Note that these requests may take some time depending on amount requested. If getting all results is mandatory, no matter how big the size, use the synchronous version. For a faster version, use async version, but not all requests are guaranteed to be returned. Generally, asynchronous execution is fine for up to 20 pages, each containing up to 200 results, yielding 4000 results within a few seconds.
Synchronous execution
$batchedTransactionsList = PromisePay::getAllResults(function($limit, $offset) {
PromisePay::BatchTransactions()->listTransactions(
array(
'limit' => $limit,
'offset' => $offset
)
);
});
Asynchronous execution
$batchedTransactionsList = PromisePay::getAllResultsAsync(function($limit, $offset) {
PromisePay::BatchTransactions()->listTransactions(
array(
'limit' => $limit,
'offset' => $offset
)
);
});
1. Fork it ( https://github.com/PromisePay/promisepay-php/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 a new Pull Request