PHP code example of bankplanet9 / milkyway-payments
1. Go to this page and download the library: Download bankplanet9/milkyway-payments library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bankplanet9 / milkyway-payments example snippets
use Bankplanet9\MilkywayPayments\MilkywayOptions;
use Bankplanet9\MilkywayPayments\MilkywayPaymentsClient;
use Bankplanet9\MilkywayPayments\Model\PayRequest;
use Bankplanet9\MilkywayPayments\Model\PrecheckRequest;
use Brick\Math\BigDecimal;
$client = new MilkywayPaymentsClient(new MilkywayOptions(
baseUrl: 'https://milkyway.stage.planet9.ae',
tokenUrl: 'https://keycloak.ac8o.planet9.ae/realms/planet9-stage/protocol/openid-connect/token',
clientId: 'your-client-id', // issued to your institution
clientSecret: 'your-client-secret',
));
// 1. Is the recipient bank's service online?
$client->healthcheck('bank-beta', 'card-payout');
// 2. Quote the payment (FX markup + commission applied here).
$quote = $client->precheck(new PrecheckRequest(
thirdPartyIdDebit: 'bank-beta',
serviceId: 'card-payout',
recipientId: 'recipient-9999',
amountCredit: BigDecimal::of('100.00'),
currencyCredit: 'USD',
));
printf("Rate %s, debit %s %s, commission %s\n",
$quote->rate, $quote->amountDebit, $quote->currencyDebit, $quote->commission);
// 3. Initiate the payment. Pass an idempotency key so retries are safe.
$transactionId = $client->pay(new PayRequest(
thirdPartyIdDebit: 'bank-beta',
serviceId: 'card-payout',
senderId: 'sender-0001',
recipientId: 'recipient-9999',
amountCredit: BigDecimal::of('100.00'),
currencyCredit: 'USD',
data: ['passport' => 'AA1234567'],
), idempotencyKey: bin2hex(random_bytes(16)));
// 4. Poll until the payment reaches a terminal status.
$result = $client->waitForCompletion($transactionId);
printf("Final status: %s\n", $result->status->name);
$client = new MilkywayPaymentsClient(
options: $options,
httpClient: $myPsr18Client, // used for API calls
// tokenHttpClient: a SEPARATE plain client for the token endpoint (must not be
// wrapped in retry/auth); defaults to its own discovered client.
requestFactory: $myPsr17RequestFactory,
streamFactory: $myPsr17StreamFactory,
);
// List every destination, or pass an ISO 3166-1 alpha-2 country to filter.
foreach ($client->discovery(country: 'TJ') as $destination) {
printf("%s (%s)\n", $destination->partnerName ?? $destination->thirdPartyId, $destination->country);
foreach ($destination->services as $service) {
printf(" - %s via %s, pays out in %s\n",
$service->serviceId,
$service->payoutMethod,
implode(', ', $service->payoutCurrencies ?? []));
}
}
// Fetch the Draft-2020 JSON Schema for a service's `data` payload. It is the same
// schema the server enforces at submit, returned as an associative array.
$schema = $client->serviceSchema('bank-beta', 'card-payout');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.