public function testShow() { $marketplaces = PromisePay::Marketplaces()->show(); $this->assertNotNull($marketplaces); $this->assertNotNull($marketplaces['id']); $this->assertNotNull($marketplaces['name']); }
public function testDeleteBankAccount() { $createBankAccount = PromisePay::BankAccount()->create($this->bankAccountData); $bankAccountId = $createBankAccount['id']; $deleteBankAccount = PromisePay::BankAccount()->delete($bankAccountId); $this->assertEquals($deleteBankAccount, 'Successfully redacted'); }
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'); }
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'); }
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)); }); }
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']); }
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'); }
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); }
/** * 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']; }
public function testGetAddressById() { $getAddress = PromisePay::Address()->get($this->addressId); $this->assertEquals($this->addressId, $getAddress['id']); }
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)); }
public static function refund($id, $params) { $response = PromisePay::RestClient('patch', 'items/' . $id . '/refund', $params); $jsonDecodedResponse = json_decode($response, true); return $jsonDecodedResponse['items']; }
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']); }
<?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');
public static function requestSessionToken($params) { $response = PromisePay::RestClient('get', 'request_session_token/', $params); $jsonDecodedResponse = json_decode($response->raw_body, true); return $jsonDecodedResponse; }
public function testRequestSessionToken() { $this->markTestSkipped(__METHOD__ . ' skipped ' . PHP_EOL); $requestSessionToken = PromisePay::Token()->requestSessionToken($this->tokenData); //var_dump($requestSessionToken); }
/** * 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; }
public static function setDisbursementAccount($id, $params) { $response = PromisePay::RestClient('post', 'users/' . $id . '/disbursement_account', $params); return json_decode($response->raw_body, true); }
/** * 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']; }
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']); }
public function testHealth() { $healthStatus = PromisePay::Tools()->getHealth(); $this->assertNotEmpty($healthStatus); }
/** * @expectedException PromisePay\Exception\ApiUnsupportedRequestMethod */ public function testInvalidRequestMethod() { PromisePay::RestClient('commit', 'items/10'); }
/** * @expectedException PromisePay\Exception\NotFound */ public function testInvokeNonExistingClass() { PromisePay::NonExistingClass()->Method(); }
public static function create($params) { $response = PromisePay::RestClient('post', 'fees/', $params); $jsonDecodedResponse = json_decode($response, true); return $jsonDecodedResponse['fees']; }
private function readmeExamples() { $cardToken = PromisePay::Token()->generateCardToken(array('token_type' => 'card', 'user_id' => 'USER_ID')); }