PHP code example of makstech / montonio-php-sdk
1. Go to this page and download the library: Download makstech/montonio-php-sdk 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/ */
makstech / montonio-php-sdk example snippets
use Montonio\MontonioClient;
$client = new MontonioClient(
$accessKey,
$secretKey,
MontonioClient::ENVIRONMENT_SANDBOX, // or ENVIRONMENT_LIVE
);
use Montonio\MontonioClient;
$httpFactory = new \Nyholm\Psr7\Factory\Psr17Factory();
$client = new MontonioClient(
$accessKey,
$secretKey,
MontonioClient::ENVIRONMENT_SANDBOX,
httpClient: new \GuzzleHttp\Client(),
requestFactory: $httpFactory,
streamFactory: $httpFactory,
);
$orderData = (new \Montonio\Structs\OrderData())
->setMerchantReference('ORDER-123')
->setReturnUrl('https://myshop.com/return')
->setNotificationUrl('https://myshop.com/webhook')
->setGrandTotal(29.99)
->setCurrency('EUR')
->setLocale('en')
->setPayment(
(new \Montonio\Structs\Payment())
->setMethod(\Montonio\Structs\Payment::METHOD_PAYMENT_INITIATION)
->setAmount(29.99)
->setCurrency('EUR')
)
->setLineItems([
[
'name' => 'T-Shirt',
'quantity' => 1,
'finalPrice' => 19.99,
],
])
->addLineItem(
(new \Montonio\Structs\LineItem())
->setName('Socks')
->setQuantity(2)
->setFinalPrice(5.00)
)
->setBillingAddress(new \Montonio\Structs\Address([
'firstName' => 'John',
'lastName' => 'Doe',
'email' => '[email protected] ',
'addressLine1' => 'Main St 1',
'locality' => 'Tallinn',
'country' => 'EE',
]));
$order = $client->orders()->createOrder($orderData);
// Redirect customer to payment
header('Location: ' . $order['paymentUrl']);
$order = $client->orders()->getOrder($orderUuid);
echo $order['paymentStatus']; // 'PAID', 'PENDING', etc.
$methods = $client->stores()->getPaymentMethods();
$link = $client->paymentLinks()->createPaymentLink(
(new \Montonio\Structs\CreatePaymentLinkData())
->setDescription('Invoice #456')
->setCurrency('EUR')
->setAmount(50.00)
->setLocale('en')
->setAskAdditionalInfo(true)
->setExpiresAt(date('c', strtotime('+7 days')))
->setType('one_time')
->setNotificationUrl('https://myshop.com/webhook')
);
echo $link['url']; // https://pay.montonio.com/...
$link = $client->paymentLinks()->getPaymentLink($linkUuid);
$refund = $client->refunds()->createRefund(
(new \Montonio\Structs\CreateRefundData())
->setOrderUuid($orderUuid)
->setAmount(10.00)
->setIdempotencyKey($uniqueKey) // V4 UUID recommended
);
echo $refund['status']; // 'PENDING'
// Order webhook: {"orderToken": "<jwt>"}
$decoded = $client->decodeToken($requestBody['orderToken']);
echo $decoded->paymentStatus; // 'PAID', 'PENDING', 'ABANDONED', etc.
echo $decoded->merchantReference;
// Refund webhook: {"refundToken": "<jwt>"}
$decoded = $client->decodeToken($requestBody['refundToken']);
echo $decoded->refundStatus; // 'SUCCESSFUL', 'PENDING', 'REJECTED', etc.
$session = $client->sessions()->createSession();
$sessionUuid = $session['uuid']; // Pass to frontend JS SDK
$orderData = (new \Montonio\Structs\OrderData())
->setPayment(
(new \Montonio\Structs\Payment())
->setMethod(\Montonio\Structs\Payment::METHOD_BLIK)
->setAmount(100.00)
->setCurrency('PLN')
->setMethodOptions(
(new \Montonio\Structs\PaymentMethodOptions())
->setBlikCode('777123')
)
)
// ... other order fields
;
// Get store balances
$balances = $client->payouts()->getBalances();
// List payouts for a store
$payouts = $client->payouts()->getPayouts($storeUuid, limit: 50, offset: 0, order: 'DESC');
// Export a payout report (excel or xml)
$export = $client->payouts()->exportPayout($storeUuid, $payoutUuid, 'excel');
$downloadUrl = $export['url'];
$carriers = $client->shipping()->carriers()->getCarriers();
// All shipping methods
$methods = $client->shipping()->shippingMethods()->getShippingMethods();
// Pickup points for a carrier
$pickupPoints = $client->shipping()->shippingMethods()
->getPickupPoints('omniva', 'EE');
// Courier services for a carrier
$courierServices = $client->shipping()->shippingMethods()
->getCourierServices('dpd', 'EE');
// Filter methods by parcel dimensions
$filtered = $client->shipping()->shippingMethods()->filterByParcels(
(new \Montonio\Structs\Shipping\FilterByParcelsData())
->setParcels([
(new \Montonio\Structs\Shipping\ShipmentParcel())->setWeight(1.5),
]),
'EE' // destination
);
// Calculate shipping rates
$rates = $client->shipping()->shippingMethods()->getRates(
(new \Montonio\Structs\Shipping\ShippingRatesData())
->setDestination('EE')
->setParcels([
(new \Montonio\Structs\Shipping\RatesParcel())->setItems([
(new \Montonio\Structs\Shipping\RatesItem())
->setLength(20.0)
->setWidth(15.0)
->setHeight(10.0)
->setWeight(0.5),
]),
])
);
$shipment = $client->shipping()->shipments()->createShipment(
(new \Montonio\Structs\Shipping\CreateShipmentData())
->setShippingMethod(
(new \Montonio\Structs\Shipping\ShipmentShippingMethod())
->setType('pickupPoint')
->setId($pickupPointId) // UUID from getPickupPoints()
)
->setReceiver(
(new \Montonio\Structs\Shipping\ShippingContact())
->setName('John Doe')
->setPhoneCountryCode('372')
->setPhoneNumber('53334770')
->setEmail('[email protected] ')
)
->setParcels([
(new \Montonio\Structs\Shipping\ShipmentParcel())->setWeight(1.0),
])
->setMerchantReference('ORDER-123')
);
echo $shipment['id'];
echo $shipment['status']; // 'pending', 'registered', etc.
// Get shipment details
$shipment = $client->shipping()->shipments()->getShipment($shipmentId);
// Update a shipment
$updated = $client->shipping()->shipments()->updateShipment($shipmentId,
(new \Montonio\Structs\Shipping\UpdateShipmentData())
->setReceiver(
(new \Montonio\Structs\Shipping\ShippingContact())
->setName('Jane Doe')
->setPhoneCountryCode('372')
->setPhoneNumber('55512345')
)
);
$labelFile = $client->shipping()->labels()->createLabelFile(
(new \Montonio\Structs\Shipping\CreateLabelFileData())
->setShipmentIds([$shipmentId])
->setPageSize('A4')
->setSynchronous(true)
);
echo $labelFile['labelFileUrl']; // PDF download URL (expires in 5 minutes)
// Get label file status
$labelFile = $client->shipping()->labels()->getLabelFile($labelFileId);
echo $labelFile['status']; // 'pending', 'ready', 'failed'
$webhook = $client->shipping()->webhooks()->createWebhook(
(new \Montonio\Structs\Shipping\CreateShippingWebhookData())
->setUrl('https://myshop.com/shipping-webhook')
->setEnabledEvents([
'shipment.registered',
'shipment.statusUpdated',
'labelFile.ready',
])
);
// List all webhooks
$webhooks = $client->shipping()->webhooks()->listWebhooks();
// Delete a webhook
$client->shipping()->webhooks()->deleteWebhook($webhookId);
shell
> composer shell
composer