/** * @param stdClass $response * * @return Payment */ private function createPaymentFromResponse(stdClass $response) { $payment = new Payment(); $payment->setShortReference($response->short_reference)->setBeneficiaryId($response->beneficiary_id)->setConversionId($response->conversion_id)->setAmount($response->amount)->setCurrency($response->currency)->setStatus($response->status)->setPaymentType($response->payment_type)->setReference($response->reference)->setReason($response->reason)->setPaymentDate(new DateTime($response->payment_date))->setTransferredAt(new DateTime($response->transferred_at))->setAuthorisationStepsRequired($response->authorisation_steps_required)->setCreatorContactId($response->creator_contact_id)->setLastUpdaterContactId($response->last_updater_contact_id)->setFailureReason($response->failure_reason)->setPayerId($response->payer_id)->setPayerDetailsSource($response->payer_details_source)->setCreatedAt(new DateTime($response->created_at))->setUpdatedAt(new DateTime($response->updated_at)); $this->setIdProperty($payment, $response->id); return $payment; }
/** * @test */ public function canFindWithSomeValues() { $data = '{"payments":[{"id":"543477161-91de-012f-e284-1e0030c7f3123","short_reference":"140416-GGJBNQ001","beneficiary_id":"543477161-91de-012f-e284-1e0030c7f352","conversion_id":"049bab6d-fe2a-42e1-be0f-531c59f838ea","amount":"1250000.00","currency":"GBP","status":"ready_to_send","payment_type":"regular","reference":"INVOICE 9876","reason":"Salary for March","payment_date":"2014-01-12T00:00:00+00:00","payer_details_source":"","transferred_at":"2014-01-12T13:00:00+00:00","authorisation_steps_required":"0","creator_contact_id":"ab3477161-91de-012f-e284-1e0030c7f35c","last_updater_contact_id":"ab3477161-91de-012f-e284-1e0030c7f35c","failure_reason":"","payer_id":"","created_at":"2014-01-12T12:24:19+00:00","updated_at":"2014-01-12T12:24:19+00:00"}],"pagination":{"total_entries":1,"total_pages":1,"current_page":1,"previous_page":-1,"next_page":-1,"per_page":25,"order":"created_at","order_asc_desc":"asc"}}'; $payment = new Payment(); $payment->setCurrency('A')->setAmount('B')->setReason('C')->setBeneficiaryId('D')->setConversionId('E')->setShortReference('F')->setStatus('G'); /* @var DateTime[] $dateTime */ $dateTime = [new DateTime(), (new DateTime())->modify('-1 hour'), (new DateTime())->modify('-2 hour'), (new DateTime())->modify('-3 hour'), (new DateTime())->modify('-4 hour'), (new DateTime())->modify('-5 hour'), (new DateTime())->modify('-6 hour'), (new DateTime())->modify('-7 hour')]; $criteria = new FindPaymentsCriteria(); $criteria->setCreatedAtFrom($dateTime[0])->setCreatedAtTo($dateTime[1])->setUpdatedAtFrom($dateTime[2])->setUpdatedAtTo($dateTime[3])->setPaymentDateFrom($dateTime[4])->setPaymentDateTo($dateTime[5])->setTransferredAtFrom($dateTime[6])->setTransferredAtTo($dateTime[7])->setAmountFrom('H')->setAmountTo('I'); $entryPoint = new PaymentsEntryPoint(new SimpleEntityManager(), $this->getMockedClient(json_decode($data), 'GET', 'payments/find', ['currency' => 'A', 'amount' => 'B', 'reason' => 'C', 'beneficiary_id' => 'D', 'conversion_id' => 'E', 'short_reference' => 'F', 'status' => 'G', 'created_at_from' => $dateTime[0]->format(DateTime::RFC3339), 'created_at_to' => $dateTime[1]->format(DateTime::RFC3339), 'updated_at_from' => $dateTime[2]->format(DateTime::RFC3339), 'updated_at_to' => $dateTime[3]->format(DateTime::RFC3339), 'payment_date_from' => $dateTime[4]->format(DateTime::RFC3339), 'payment_date_to' => $dateTime[5]->format(DateTime::RFC3339), 'transferred_at_from' => $dateTime[6]->format(DateTime::RFC3339), 'transferred_at_to' => $dateTime[7]->format(DateTime::RFC3339), 'amount_from' => 'H', 'amount_to' => 'I', 'on_behalf_of' => 'J', 'page' => null, 'per_page' => null, 'order' => null, 'order_asc_desc' => null])); $payments = $entryPoint->find($payment, $criteria, null, 'J'); $this->assertInstanceOf(Payments::class, $payments); $list = $payments->getPayments(); $this->assertArrayHasKey(0, $list); $this->assertCount(1, $list); $this->validateObjectStrictName($list[0], json_decode($data, true)['payments'][0]); }
#!/usr/bin/env php <?php use CurrencyCloud\CurrencyCloud; use CurrencyCloud\Model\Beneficiary; use CurrencyCloud\Model\Conversion; use CurrencyCloud\Model\Payment; use CurrencyCloud\Session; require_once __DIR__ . '/../vendor/autoload.php'; $session = new Session(Session::ENVIRONMENT_DEMONSTRATION, '<user-id>', '<api-key>'); $currencyCloud = CurrencyCloud::createDefault($session); //Note that there is no direct call to authenticate api $detailedRate = $currencyCloud->rates()->detailed('EUR', 'GBP', 'buy', '10000.00'); var_dump($detailedRate); $conversion = Conversion::create('EUR', 'GBP', 'buy'); $conversion = $currencyCloud->conversions()->create($conversion, '10000.00', 'Invoice Payment', true); var_dump($conversion); $beneficiaryRequiredDetails = $currencyCloud->reference()->beneficiaryRequiredDetails('EUR', 'DE'); var_dump($beneficiaryRequiredDetails); $beneficiary = Beneficiary::create('Acme GmbH', 'DE', 'EUR', 'John Doe')->setBeneficiaryCountry('DE')->setBicSwift('COBADEFF')->setIban('DE89370400440532013000'); $beneficiary = $currencyCloud->beneficiaries()->create($beneficiary); var_dump($beneficiary); $payment = Payment::create('EUR', $beneficiary->getId(), '10000', 'Invoice Payment', 'Invoice 1234')->setPaymentType('regular')->setConversionId($conversion->getId()); $payment = $currencyCloud->payments()->create($payment); var_dump($payment);