Skip to content

Commit ff08e11

Browse files
Adds payments tracking info endpoint (#98)
1 parent d21890c commit ff08e11

File tree

3 files changed

+1214
-0
lines changed

3 files changed

+1214
-0
lines changed

src/EntryPoint/PaymentsEntryPoint.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
use CurrencyCloud\Model\PaymentDeliveryDate;
1313
use CurrencyCloud\Model\Payments;
1414
use CurrencyCloud\Model\PaymentSubmission;
15+
use CurrencyCloud\Model\PurposeCode;
1516
use CurrencyCloud\Model\QuotePaymentFee;
17+
use CurrencyCloud\Model\PaymentTrackingInfo;
1618
use DateTime;
1719
use stdClass;
1820

@@ -405,4 +407,91 @@ public function getQuotePaymentFee($paymentCurrency, $paymentDestinationCountry,
405407
$response->payment_type, $response->charge_type, $response->fee_amount, $response->fee_currency);
406408
}
407409

410+
/**
411+
* @param string $id
412+
*
413+
* @return PaymentTrackingInfo
414+
*/
415+
public function getTrackingInfo($id)
416+
{
417+
$response = $this->request('GET',
418+
sprintf('payments/%s/tracking_info', $id));
419+
420+
return $this->createTrackingInfoFromResponse($response);
421+
}
422+
423+
/**
424+
* @param stdClass $response
425+
*
426+
* @return PaymentTrackingInfo
427+
*/
428+
private function createTrackingInfoFromResponse(stdClass $response)
429+
{
430+
$trackingInfo = new PaymentTrackingInfo();
431+
$trackingInfo->setUetr($response->uetr);
432+
$trackingInfo->setTransactionStatus(
433+
new PaymentTrackingInfo\TransactionStatus($response->transaction_status->status,
434+
$response->transaction_status->reason));
435+
$trackingInfo->setCompletionTime(null !== $response->completion_time ?
436+
new DateTime($response->completion_time) : null);
437+
$trackingInfo->setInitiationTime(null !== $response->initiation_time ?
438+
new DateTime($response->initiation_time) : null);
439+
$trackingInfo->setLastUpdateTime(null !== $response->last_update_time ?
440+
new DateTime($response->last_update_time) : null);
441+
442+
$paymentEvents = [];
443+
foreach ($response->payment_events as $paymentEvent) {
444+
$paymentEvents[] = $this->createTrackingInfoPaymentEventFromResponse($paymentEvent);
445+
}
446+
$trackingInfo->setPaymentEvents($paymentEvents);
447+
return $trackingInfo;
448+
}
449+
450+
/**
451+
* @param stdClass $paymentEventResponse
452+
*
453+
* @return PaymentTrackingInfo\PaymentEvent
454+
*/
455+
private function createTrackingInfoPaymentEventFromResponse(stdClass $paymentEventResponse)
456+
{
457+
$paymentEvent = new PaymentTrackingInfo\PaymentEvent();
458+
$paymentEvent->setForwardedToAgent($paymentEventResponse->forwarded_to_agent);
459+
$paymentEvent->setFrom($paymentEventResponse->from);
460+
$paymentEvent->setFundsAvailable($paymentEventResponse->funds_available);
461+
$paymentEvent->setOriginator($paymentEventResponse->originator);
462+
$paymentEvent->setTo($paymentEventResponse->to);
463+
$paymentEvent->setTrackerEventType($paymentEventResponse->tracker_event_type);
464+
$paymentEvent->setTransactionStatus(null !== $paymentEventResponse->transaction_status ?
465+
new PaymentTrackingInfo\TransactionStatus($paymentEventResponse->transaction_status->status,
466+
$paymentEventResponse->transaction_status->reason) : null);
467+
$paymentEvent->setValid($paymentEventResponse->valid);
468+
$paymentEvent->setSerialParties(null !== $paymentEventResponse->serial_parties ?
469+
new PaymentTrackingInfo\SerialParties($paymentEventResponse->serial_parties->debtor,
470+
$paymentEventResponse->serial_parties->debtor_agent,
471+
$paymentEventResponse->serial_parties->intermediary_agent1,
472+
$paymentEventResponse->serial_parties->instructing_reimbursement_agent,
473+
$paymentEventResponse->serial_parties->creditor_agent,
474+
$paymentEventResponse->serial_parties->creditor) : null);
475+
$paymentEvent->setSenderAcknowledgementReceipt(null !== $paymentEventResponse->sender_acknowledgement_receipt ?
476+
new DateTime($paymentEventResponse->sender_acknowledgement_receipt) : null);
477+
$paymentEvent->setInstructedAmount(null !== $paymentEventResponse->instructed_amount ?
478+
new PaymentTrackingInfo\Amount($paymentEventResponse->instructed_amount->currency, $paymentEventResponse->instructed_amount->amount) : null);
479+
$paymentEvent->setConfirmedAmount(null !== $paymentEventResponse->confirmed_amount ?
480+
new PaymentTrackingInfo\Amount($paymentEventResponse->confirmed_amount->currency, $paymentEventResponse->confirmed_amount->amount) : null);
481+
$paymentEvent->setInterbankSettlementAmount(null !== $paymentEventResponse->interbank_settlement_amount ?
482+
new PaymentTrackingInfo\Amount($paymentEventResponse->interbank_settlement_amount->currency, $paymentEventResponse->interbank_settlement_amount->amount) : null);
483+
$paymentEvent->setInterbankSettlementDate(null !== $paymentEventResponse->interbank_settlement_date ?
484+
new DateTime($paymentEventResponse->interbank_settlement_date) : null);
485+
$paymentEvent->setChargeAmount(null !== $paymentEventResponse->charge_amount ?
486+
new PaymentTrackingInfo\Amount($paymentEventResponse->charge_amount->currency, $paymentEventResponse->charge_amount->amount) : null);
487+
$paymentEvent->setChargeType($paymentEventResponse->charge_type);
488+
$paymentEvent->setForeignExchangeDetails(null !== $paymentEventResponse->foreign_exchange_details ?
489+
new PaymentTrackingInfo\ForeignExchangeDetails($paymentEventResponse->foreign_exchange_details->source_currency,
490+
$paymentEventResponse->foreign_exchange_details->target_currency,
491+
$paymentEventResponse->foreign_exchange_details->rate) : null);
492+
$paymentEvent->setLastUpdateTime(null !== $paymentEventResponse->last_update_time ?
493+
new DateTime($paymentEventResponse->last_update_time) : null);
494+
495+
return $paymentEvent;
496+
}
408497
}

0 commit comments

Comments
 (0)