Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 49 additions & 3 deletions lib/Trolley/BalanceGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ public function __construct($gateway)
*/
public function search($params, $query)
{
$response = $this->_http->get('/v1/balances/'.$params, $query);
$path = $params ? "/v1/balances/{$params}" : '/v1/balances';
$response = $this->_http->get($path, $query);


if ($response['ok']) {
$pager = [
'object' => $this,
'method' => 'search',
'methodArgs' => $query
'method' => 'searchPage',
'methodArgs' => array_merge($query, ['params' => $params])
];

$items = array_map(function ($item) {
Expand All @@ -63,6 +64,51 @@ public function search($params, $query)
throw new Exception\DownForMaintenance();
}
}

public function searchPage($query)
{
$params = isset($query['params']) ? $query['params'] : '';
unset($query['params']);
return $this->search($params, $query);
}

public function all($query = [])
{
$response = $this->_http->get('/v1/balances', $query);
return $this->balancesCollection($response, 'all', $query);
}

public function paymentrails($query = [])
{
$response = $this->_http->get('/v1/balances/paymentrails', $query);
return $this->balancesCollection($response, 'paymentrails', $query);
}

public function paypal($query = [])
{
$response = $this->_http->get('/v1/balances/paypal', $query);
return $this->balancesCollection($response, 'paypal', $query);
}

private function balancesCollection($response, $method, $query)
{
if ($response['ok']) {
$pager = [
'object' => $this,
'method' => $method,
'methodArgs' => $query
];

$items = array_map(function ($item) {
return Balance::factory($item);
}, $response['balances']);
return new ResourceCollection($response, $items, $pager);
} else if ($response['errors']) {
throw new Exception\Standard($response['errors']);
} else {
throw new Exception\DownForMaintenance();
}
}
}

class_alias('Trolley\BalanceGateway', 'Trolley_BalanceGateway');
8 changes: 6 additions & 2 deletions lib/Trolley/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class Batch extends Base
"status" => "",
"totalPayments" => "",
"updatedAt" => "",
"payments" => ""
"payments" => "",
"quoteExpiredAt" => "",
"tags" => ""
];

/**
Expand Down Expand Up @@ -240,7 +242,9 @@ protected function _initialize($attributes) {
"status",
"totalPayments",
"updatedAt",
"payments" => 'Trolley\Payment::factoryArray'
"payments" => 'Trolley\Payment::factoryArray',
"quoteExpiredAt",
"tags"
];

foreach ($fields as $key => $field) {
Expand Down
33 changes: 18 additions & 15 deletions lib/Trolley/BatchGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function search($query)
* Fetch a Batch by ID
*/
public function find($id) {
$response = $this->_http->get('/v1/batches/' . $id, null);
$response = $this->_http->get("/v1/batches/{$id}", null);

if ($response['ok']) {
return Batch::factory($response['batch']);
Expand All @@ -92,7 +92,7 @@ public function create($attrib, $payments = []) {
}

public function update($batchId, $attrib) {
$response = $this->_http->patch('/v1/batches/' . $batchId, $attrib);
$response = $this->_http->patch("/v1/batches/{$batchId}", $attrib);
if ($response['ok']) {
return true;
} else if ($response['errors']){
Expand All @@ -103,7 +103,7 @@ public function update($batchId, $attrib) {
}

public function delete($batchId) {
$response = $this->_http->delete('/v1/batches/' . $batchId);
$response = $this->_http->delete("/v1/batches/{$batchId}");
if ($response['ok']) {
return true;
} else if ($response['errors']){
Expand All @@ -125,7 +125,7 @@ public function deleteMultiple($batchIds) {
}

public function summary($batchId) {
$response = $this->_http->get('/v1/batches/' . $batchId . '/summary');
$response = $this->_http->get("/v1/batches/{$batchId}/summary");
if ($response['ok']) {
return BatchSummary::factory($response['batchSummary']);
} else if ($response['errors']){
Expand All @@ -136,7 +136,7 @@ public function summary($batchId) {
}

public function generateQuote($batchId) {
$response = $this->_http->post('/v1/batches/' . $batchId . '/generate-quote');
$response = $this->_http->post("/v1/batches/{$batchId}/generate-quote");
if ($response['ok']) {
return true;
} else if ($response['errors']){
Expand All @@ -147,7 +147,7 @@ public function generateQuote($batchId) {
}

public function startProcessing($batchId) {
$response = $this->_http->post('/v1/batches/' . $batchId . '/start-processing');
$response = $this->_http->post("/v1/batches/{$batchId}/start-processing");
if ($response['ok']) {
return true;
} else if ($response['errors']){
Expand All @@ -158,7 +158,7 @@ public function startProcessing($batchId) {
}

public function createPayment($batchId, $payment) {
$response = $this->_http->post('/v1/batches/' . $batchId . '/payments', $payment);
$response = $this->_http->post("/v1/batches/{$batchId}/payments", $payment);
if ($response['ok']) {
return Payment::factory($response['payment']);
} else if ($response['errors']){
Expand All @@ -169,7 +169,7 @@ public function createPayment($batchId, $payment) {
}

public function findPayment($batchId, $paymentId) {
$response = $this->_http->get('/v1/batches/' . $batchId . '/payments/' . $paymentId);
$response = $this->_http->get("/v1/batches/{$batchId}/payments/{$paymentId}");
if ($response['ok']) {
return Payment::factory($response['payment']);
} else if ($response['errors']){
Expand All @@ -180,7 +180,7 @@ public function findPayment($batchId, $paymentId) {
}

public function updatePayment($batchId, $paymentId, $params) {
$response = $this->_http->patch('/v1/batches/' . $batchId . '/payments/' . $paymentId, $params);
$response = $this->_http->patch("/v1/batches/{$batchId}/payments/{$paymentId}", $params);
if ($response['ok']) {
return true;
} else if ($response['errors']){
Expand All @@ -191,7 +191,7 @@ public function updatePayment($batchId, $paymentId, $params) {
}

public function deletePayment($batchId, $paymentId) {
$response = $this->_http->delete('/v1/batches/' . $batchId . '/payments/' . $paymentId);
$response = $this->_http->delete("/v1/batches/{$batchId}/payments/{$paymentId}");
if ($response['ok']) {
return true;
} else if ($response['errors']){
Expand All @@ -202,18 +202,21 @@ public function deletePayment($batchId, $paymentId) {
}

public function payments($batchId, $params = []) {
return $this->paymentsInternal(
array_merge(['batchId' => $batchId], $params)
);
$response = $this->_http->get("/v1/batches/{$batchId}/payments", $params);
return $this->paymentsCollection($response, $batchId, $params);
}

public function paymentsInternal($params) {
$response = $this->_http->get('/v1/batches/' . $params['batchId'] . '/payments', $params);
$response = $this->_http->get("/v1/batches/{$params['batchId']}/payments", $params);
return $this->paymentsCollection($response, $params['batchId'], $params);
}

private function paymentsCollection($response, $batchId, $params) {
if ($response['ok']) {
$pager = [
'object' => $this,
'method' => 'paymentsInternal',
'methodArgs' => $params,
'methodArgs' => array_merge($params, ['batchId' => $batchId]),
];

$items = array_map(function ($item) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Trolley/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Configuration
{
public static $global;

private $_environment = null;
private $_environment = "production";
private $_merchantId = null;
private $_publicKey = null;
private $_privateKey = null;
Expand Down
16 changes: 16 additions & 0 deletions lib/Trolley/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ public function balance()
{
return new BalanceGateway($this);
}

/**
* @return VerificationGateway
*/
public function verification()
{
return new VerificationGateway($this);
}

/**
* @return VerificationGateway
*/
public function trust()
{
return $this->verification();
}
}

class_alias('Trolley\Gateway', 'Trolley_Gateway');
18 changes: 16 additions & 2 deletions lib/Trolley/InvoicePayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ class InvoicePayment extends Base
"invoiceId" => "",
"invoiceLineId" => "",
"paymentId" => "",
"amount" => ""
"amount" => "",
"batchId" => "",
"invoicePayments" => "",
"status" => "",
"memo" => "",
"externalId" => "",
"tags" => "",
"coverFees" => ""
Comment thread
cursor[bot] marked this conversation as resolved.
];

/**
Expand Down Expand Up @@ -95,7 +102,14 @@ protected function _initialize($attributes) {
"invoiceId",
"invoiceLineId",
"paymentId",
"amount"
"amount",
"batchId",
"invoicePayments",
"status",
"memo",
"externalId",
"tags",
"coverFees"
];

foreach ($fields as $key => $field) {
Expand Down
4 changes: 4 additions & 0 deletions lib/Trolley/OfflinePayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class OfflinePayment extends Base
"updatedAt" => "",
"createdAt" => "",
"deletedAt" => "",
"activityCount" => "",
"taxReportable" => "",
];

/**
Expand Down Expand Up @@ -132,6 +134,8 @@ protected function _initialize($attributes) {
"updatedAt",
"createdAt",
"deletedAt",
"activityCount",
"taxReportable",
];

foreach ($fields as $field) {
Expand Down
8 changes: 4 additions & 4 deletions lib/Trolley/OfflinePaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct($gateway)
public function search($query)
{
if (isset($query["recipientId"])) {
$response = $this->_http->get('/v1/recipients/'.$query["recipientId"].'/offlinePayments', $query);
$response = $this->_http->get("/v1/recipients/{$query['recipientId']}/offlinePayments", $query);
} else {
$response = $this->_http->get('/v1/offline-payments', $query);
}
Expand All @@ -70,7 +70,7 @@ public function search($query)
}

public function create($recipientId, $offlinePaymentBody) {
$response = $this->_http->post('/v1/recipients/' . $recipientId . '/offlinePayments', $offlinePaymentBody);
$response = $this->_http->post("/v1/recipients/{$recipientId}/offlinePayments", $offlinePaymentBody);
if ($response['ok']) {
return OfflinePayment::factory($response['offlinePayment']);
} else if ($response['errors']){
Expand All @@ -81,7 +81,7 @@ public function create($recipientId, $offlinePaymentBody) {
}

public function update($recipientId, $offlinePaymentId, $offlinePaymentBody) {
$response = $this->_http->patch('/v1/recipients/' . $recipientId . '/offlinePayments/' . $offlinePaymentId, $offlinePaymentBody);
$response = $this->_http->patch("/v1/recipients/{$recipientId}/offlinePayments/{$offlinePaymentId}", $offlinePaymentBody);
if ($response['ok']) {
return true;
} else if ($response['errors']){
Expand All @@ -92,7 +92,7 @@ public function update($recipientId, $offlinePaymentId, $offlinePaymentBody) {
}

public function delete($recipientId, $offlinePaymentId) {
$response = $this->_http->delete('/v1/recipients/' . $recipientId . '/offlinePayments/' . $offlinePaymentId);
$response = $this->_http->delete("/v1/recipients/{$recipientId}/offlinePayments/{$offlinePaymentId}");
if ($response['ok']) {
return true;
} else if ($response['errors']){
Expand Down
Loading