public function testShow()
 {
     $marketplaces = PromisePay::Marketplaces()->show();
     $this->assertNotNull($marketplaces);
     $this->assertNotNull($marketplaces['id']);
     $this->assertNotNull($marketplaces['name']);
 }
Exemplo n.º 2
0
 public function testDeleteBankAccount()
 {
     $createBankAccount = PromisePay::BankAccount()->create($this->bankAccountData);
     $bankAccountId = $createBankAccount['id'];
     $deleteBankAccount = PromisePay::BankAccount()->delete($bankAccountId);
     $this->assertEquals($deleteBankAccount, 'Successfully redacted');
 }
Exemplo n.º 3
0
 public function testEditCompany()
 {
     $this->companyInfo['name'] = 'Modified company name';
     $companyUpdate = PromisePay::Company()->update($this->companyId, $this->companyInfo);
     $this->assertEquals($this->companyInfo['legal_name'], $companyUpdate['legal_name']);
     $this->assertEquals($this->companyInfo['name'], $companyUpdate['name']);
 }
 private function readmeExamples()
 {
     // List Batch Transactions
     $batches = PromisePay::BatchTransactions()->listTransactions();
     // Show Batch Transaction
     $batch = PromisePay::BatchTransactions()->showTransaction('BATCH_TRANSACTION_ID');
 }
Exemplo n.º 5
0
 public function testList()
 {
     $createFee = PromisePay::Fee()->create($this->feeData);
     $getList = PromisePay::Fee()->getList(200);
     //var_dump($createFee, $getList);
     $this->markTestSkipped(__METHOD__ . ' skipped ' . PHP_EOL);
 }
 public function testDeletePayPalAccount()
 {
     // Create a PayPal Account
     $createPayPalAccount = PromisePay::PayPalAccount()->create($this->payPalData);
     // Then, delete it
     $deletePayPalAccount = PromisePay::PayPalAccount()->delete($createPayPalAccount['id']);
     $this->assertEquals($deletePayPalAccount, 'Successfully redacted');
 }
Exemplo n.º 7
0
 private function readmeExamples()
 {
     $batchedTransactionsList = PromisePay::getAllResults(function ($limit, $offset) {
         PromisePay::BatchTransactions()->listTransactions(array('limit' => $limit, 'offset' => $offset));
     });
     $batchedTransactionsList = PromisePay::getAllResultsAsync(function ($limit, $offset) {
         PromisePay::BatchTransactions()->listTransactions(array('limit' => $limit, 'offset' => $offset));
     });
 }
Exemplo n.º 8
0
 public function testListCardAccountsForUser()
 {
     // First, create the user
     $createUser = PromisePay::User()->create($this->userData);
     // Update the cardAccountData
     $this->cardAccountData['user_id'] = $createUser['id'];
     // Create the Card Account
     $createAccount = PromisePay::CardAccount()->create($this->cardAccountData);
     $user = PromisePay::CardAccount()->getUser($createAccount['id']);
     $this->assertEquals($this->cardAccountData['full_name'], $user['full_name']);
 }
Exemplo n.º 9
0
 private function readmeExamples()
 {
     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);
 }
 private function readmeExamples()
 {
     // CREATE
     $configuration = PromisePay::Configurations()->create(array('name' => 'partial_refunds', 'enabled' => true));
     // GET
     $configuration = PromisePay::Configurations()->get('ca321b3f-db87-4d75-ba05-531c7f1bb515');
     // GET LIST
     $configurations = PromisePay::Configurations()->getList();
     // UPDATE
     $configuration = PromisePay::Configurations()->update(array('id' => 'ca321b3f-db87-4d75-ba05-531c7f1bb515', 'max' => 12345, 'name' => 'partial_refunds', 'enabled' => true));
     // DELETE
     PromisePay::Configurations()->delete('ca321b3f-db87-4d75-ba05-531c7f1bb515');
 }
Exemplo n.º 11
0
 public function testList()
 {
     $createFee = PromisePay::Fee()->create($this->feeData);
     $limit = 200;
     $offset = 0;
     while (true) {
         $getList = PromisePay::Fee()->getList(array('limit' => $limit, 'offset' => $offset));
         foreach ($getList as $fee) {
             if ($fee['id'] == $createFee['id']) {
                 $feeFound = true;
                 break 2;
             }
         }
         $getListCount = count($getList);
         if ($getListCount < $limit) {
             break;
         }
         $offset += $getListCount;
     }
     $this->assertTrue($feeFound);
 }
Exemplo n.º 12
0
 /**
  * Method for performing async requests against PromisePay endpoints.
  *
  * In case all requests don't get processed in the same batch,
  * because the API server has a limit of requests it's willing
  * to fullfil in a certain amount of time, then this method
  * will call itself recursively until all requests have been processed, unless:
  * 1) iterator count exceeds $iteratorMaximum param
  * 2) not a single new 2xx response is received in the last 2 batches
  *
  * @param array $requests A set of requests, in format of [http method, full uri]
  * @param int $iteratorMaximum Maximum amount of recursive method calls
  */
 public function Client(array $requests, $iteratorMaximum = 1)
 {
     $multiHandle = curl_multi_init();
     $connections = array();
     foreach ($requests as $index => $requestParams) {
         list($method, $uri) = $requestParams;
         $connections[$index] = curl_init($uri);
         if (PromisePay::isDebug()) {
             fwrite(STDOUT, "#{$index} => {$uri} added." . PHP_EOL);
         }
         curl_setopt($connections[$index], CURLOPT_URL, $uri);
         curl_setopt($connections[$index], CURLOPT_HEADER, true);
         curl_setopt($connections[$index], CURLOPT_RETURNTRANSFER, true);
         curl_setopt($connections[$index], CURLOPT_CUSTOMREQUEST, strtoupper($method));
         curl_setopt($connections[$index], CURLOPT_USERAGENT, 'promisepay-php-sdk/1.0');
         curl_setopt($connections[$index], CURLOPT_USERPWD, sprintf('%s:%s', constant(Functions::getBaseNamespace() . '\\API_LOGIN'), constant(Functions::getBaseNamespace() . '\\API_PASSWORD')));
         curl_multi_add_handle($multiHandle, $connections[$index]);
     }
     $active = false;
     do {
         $multiProcess = curl_multi_exec($multiHandle, $active);
     } while ($multiProcess === CURLM_CALL_MULTI_PERFORM);
     while ($active && $multiProcess === CURLM_OK) {
         if (curl_multi_select($multiHandle) === -1) {
             // if there's a problem at the moment, delay execution
             // by 100 miliseconds, as suggested on
             // https://curl.haxx.se/libcurl/c/curl_multi_fdset.html
             if (PromisePay::isDebug()) {
                 fwrite(STDOUT, "Pausing for 100 miliseconds." . PHP_EOL);
             }
             usleep(100000);
         }
         do {
             $multiProcess = curl_multi_exec($multiHandle, $active);
         } while ($multiProcess === CURLM_CALL_MULTI_PERFORM);
     }
     foreach ($connections as $index => $connection) {
         $response = curl_multi_getcontent($connection);
         // we're gonna separate headers and response body
         $responseHeaders = curl_getinfo($connection);
         $responseBody = trim(substr($response, $responseHeaders['header_size']));
         if (PromisePay::isDebug()) {
             fwrite(STDOUT, sprintf("#{$index} content: %s" . PHP_EOL, $responseBody));
             fwrite(STDOUT, "#{$index} headers: " . print_r($responseHeaders, true) . PHP_EOL);
         }
         $jsonArray = json_decode($responseBody, true);
         if (substr($responseHeaders['http_code'], 0, 1) == '2' && is_array($jsonArray)) {
             // processed successfully, remove from queue
             foreach ($requests as $index => $requestParams) {
                 list($method, $url) = $requestParams;
                 if ($url == $responseHeaders['url']) {
                     if (PromisePay::isDebug()) {
                         fwrite(STDOUT, "Unsetting {$index} from requests." . PHP_EOL);
                     }
                     unset($requests[$index]);
                 }
             }
             // SCENARIO #1
             // Response JSON is self-contained under a master key
             foreach (PromisePay::$usedResponseIndexes as $responseIndex) {
                 if (isset($jsonArray[$responseIndex])) {
                     $jsonArray = $jsonArray[$responseIndex];
                     break;
                 } else {
                     unset($responseIndex);
                 }
             }
             // SCENARIO #2
             // Response JSON is NOT self-contained under a master key
             if (!isset($responseIndex)) {
                 // for these scenarios, we'll store them under their endpoint name.
                 // for example, requestSessionToken() internally calls getDecodedResponse()
                 // without a key param.
                 $responseIndex = trim(parse_url($responseHeaders['url'], PHP_URL_PATH), '/');
                 $slashLookup = strpos($responseIndex, '/');
                 if ($slashLookup !== false) {
                     $responseIndex = substr($responseIndex, 0, $slashLookup);
                 }
             }
         } else {
             if (PromisePay::isDebug()) {
                 fwrite(STDOUT, 'An invalid response was received: ' . PHP_EOL . $responseBody . PHP_EOL);
             }
             // handle errors
             $responseIndex = array_keys($jsonArray);
             $responseIndex = $responseIndex[0];
         }
         $this->responses[$responseIndex][] = $jsonArray;
         $this->storageHandler->storeJson($jsonArray);
         $this->storageHandler->storeMeta(PromisePay::getMeta($jsonArray));
         $this->storageHandler->storeLinks(PromisePay::getLinks($jsonArray));
         $this->storageHandler->storeDebug($responseHeaders);
         unset($responseIndex);
         curl_multi_remove_handle($multiHandle, $connection);
     }
     curl_multi_close($multiHandle);
     $this->pendingRequestsHistoryCounts[] = count($requests);
     if (PromisePay::isDebug()) {
         fwrite(STDOUT, sprintf("responses contains %d members." . PHP_EOL, count($this->responses)));
     }
     // if a single request hasn't succeeded in the past 2 request batches,
     // terminate and return result.
     foreach ($this->pendingRequestsHistoryCounts as $index => $pendingRequestsCount) {
         if ($index === 0) {
             continue;
         }
         if ($this->pendingRequestsHistoryCounts[$index - 1] == $pendingRequestsCount) {
             if (PromisePay::isDebug()) {
                 fwrite(STDOUT, 'Server 5xx detected; returning what was obtained thus far.' . PHP_EOL);
             }
             return $this->storageHandler;
         }
     }
     $this->iteratorCount++;
     if (empty($requests) || $this->iteratorCount >= $iteratorMaximum) {
         return $this->storageHandler;
     }
     if (PromisePay::isDebug()) {
         fwrite(STDOUT, PHP_EOL . '<<STARTING RECURSIVE CALL>>' . PHP_EOL);
         fwrite(STDOUT, 'REMAINING REQUESTS: ' . print_r($requests, true) . PHP_EOL . 'PROCESSED RESPONSES: ' . print_r($this->responses, true));
     }
     return $this->Client($requests);
 }
 public static function getUser($id)
 {
     $response = PromisePay::RestClient('get', 'card_accounts/' . $id . '/users');
     $jsonDecodedResponse = json_decode($response->raw_body, true);
     return $jsonDecodedResponse['users'];
 }
Exemplo n.º 14
0
 public function testGetAddressById()
 {
     $getAddress = PromisePay::Address()->get($this->addressId);
     $this->assertEquals($this->addressId, $getAddress['id']);
 }
Exemplo n.º 15
0
 public function testGetFee()
 {
     $getFee = PromisePay::Transaction()->getFee($this->transactionId);
     $this->assertTrue(is_array($getFee));
 }
 private function readmeExamples()
 {
     // SHOW
     $wallet = PromisePay::WalletAccounts()->show('WALLET_ID');
     // SHOW ACCOUNT USER
     $walletUser = PromisePay::WalletAccounts()->getUser('WALLET_ID');
     // DEPOSIT
     // 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));
     // WITHDRAW
     // 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));
 }
Exemplo n.º 17
0
 public static function refund($id, $params)
 {
     $response = PromisePay::RestClient('patch', 'items/' . $id . '/refund', $params);
     $jsonDecodedResponse = json_decode($response, true);
     return $jsonDecodedResponse['items'];
 }
Exemplo n.º 18
0
 public function testValidateRoutingNumber()
 {
     $validateRoutingNumber = PromisePay::BankAccount()->validateRoutingNumber($this->bankAccountData['routing_number']);
     $this->assertTrue(is_array($validateRoutingNumber));
     $this->assertEquals($validateRoutingNumber['routing_number'], $this->bankAccountData['routing_number']);
 }
Exemplo n.º 19
0
<?php

namespace PromisePay\Tests;

use PromisePay\PromisePay;
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
$composerAutoloadFile = __DIR__ . '/../../../autoload.php';
if (is_file($composerAutoloadFile)) {
    require_once $composerAutoloadFile;
}
// Tests/PHPunit specific files
require_once __DIR__ . '/GUID.php';
require_once __DIR__ . '/functions.php';
// Project files autoloader
require __DIR__ . '/../autoload.php';
// Setup testing environment
PromisePay::Configuration()->environment('prelive');
PromisePay::Configuration()->login('*****@*****.**');
PromisePay::Configuration()->password('d897f812e8485728e1de7d8ae092b75a');
Exemplo n.º 20
0
 public static function requestSessionToken($params)
 {
     $response = PromisePay::RestClient('get', 'request_session_token/', $params);
     $jsonDecodedResponse = json_decode($response->raw_body, true);
     return $jsonDecodedResponse;
 }
Exemplo n.º 21
0
 public function testRequestSessionToken()
 {
     $this->markTestSkipped(__METHOD__ . ' skipped ' . PHP_EOL);
     $requestSessionToken = PromisePay::Token()->requestSessionToken($this->tokenData);
     //var_dump($requestSessionToken);
 }
Exemplo n.º 22
0
 /**
  * Request Token Auths
  *
  * == Example $params ==
  *
  * Card Token :
  * [ 'token_type' => 'card', 'user_id' => $user_id ]
  *
  * Approve token :
  * [ 'token_type' => 4, 'email' => $marketplace_users_email, 'password' => $marketplace_users_password ]
  *
  * EUI token :
  * // Not available yet
  *
  * http://reference.promisepay.com/docs/generate-a-card-token
  *
  * @since 1.2 As per https://promisepay-api.readme.io/docs/generate-a-card-token
  * @param  array $params
  * @return array JSON decoded API response
  */
 public static function requestTokenAuths($params)
 {
     $response = PromisePay::RestClient('post', 'token_auths/', $params);
     $jsonDecodedResponse = json_decode($response->raw_body, true);
     return $jsonDecodedResponse;
 }
Exemplo n.º 23
0
 public static function setDisbursementAccount($id, $params)
 {
     $response = PromisePay::RestClient('post', 'users/' . $id . '/disbursement_account', $params);
     return json_decode($response->raw_body, true);
 }
Exemplo n.º 24
0
 /**
  * Update existing company.
  * Expects Company object and company id (in form of "ec9bf096-c505-4bef-87f6-18822b9dbf2c").
  *
  * @param Company $company
  * @param string $id
  * @return array
  */
 public static function update($id, $params)
 {
     $response = PromisePay::RestClient('patch', 'companies/' . $id, $params);
     $jsonDecodedResponse = json_decode($response->raw_body, true);
     return $jsonDecodedResponse['companies'];
 }
Exemplo n.º 25
0
 public function testSetDisbursementAccount()
 {
     // First, create the user
     $createUser = PromisePay::User()->create($this->userData);
     // Alias newly created user id for the sake of clarity
     $UID = $createUser['id'];
     // setDisbursementAccount requires Bank or PayPal account param.
     // We're gonna go for PayPal.
     // Update PayPal account data with the id of just created user
     $this->payPalData['user_id'] = $UID;
     // Create a PayPal Account
     $createPayPalAccount = PromisePay::PayPalAccount()->create($this->payPalData);
     $setDisbursementAccount = PromisePay::User()->setDisbursementAccountV2($UID, array('account_id' => $createPayPalAccount['id']));
     $this->assertEquals($createPayPalAccount['id'], $setDisbursementAccount['related']['payout_account']);
 }
Exemplo n.º 26
0
 public function testHealth()
 {
     $healthStatus = PromisePay::Tools()->getHealth();
     $this->assertNotEmpty($healthStatus);
 }
Exemplo n.º 27
0
 /**
  * @expectedException PromisePay\Exception\ApiUnsupportedRequestMethod
  */
 public function testInvalidRequestMethod()
 {
     PromisePay::RestClient('commit', 'items/10');
 }
Exemplo n.º 28
0
 /**
  * @expectedException PromisePay\Exception\NotFound
  */
 public function testInvokeNonExistingClass()
 {
     PromisePay::NonExistingClass()->Method();
 }
Exemplo n.º 29
0
 public static function create($params)
 {
     $response = PromisePay::RestClient('post', 'fees/', $params);
     $jsonDecodedResponse = json_decode($response, true);
     return $jsonDecodedResponse['fees'];
 }
Exemplo n.º 30
0
 private function readmeExamples()
 {
     $cardToken = PromisePay::Token()->generateCardToken(array('token_type' => 'card', 'user_id' => 'USER_ID'));
 }