myropayme / myropay-php
Official PHP library for the MyroPay API
dev-main
2026-07-13 12:09 UTC
Requires
- php: >=7.4
- ext-curl: *
- ext-json: *
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-22 03:54:41 UTC
README
Official PHP library for the MyroPay API. Only requires the curl and json extensions (both bundled with PHP by default) — no other dependencies.
Install
composer require myropayme/myropay-php
Usage
require_once('vendor/autoload.php'); \Myropay\Myropay::setApiKey('sk_test_...'); $charge = \Myropay\Charge::create([ 'email' => 'customer@email.com', 'amount' => 500000, // whole currency units — ₦500,000, not kobo 'currency' => 'NGN', // optional, defaults to NGN 'reference' => 'ORD-1029', // optional, your own order id ]); header('Location: ' . $charge['checkout_url']);
Retrieve a charge later:
$charge = \Myropay\Charge::retrieve('cs_test_...'); if ($charge['status'] === 'completed') { // fulfil the order }
Important
- Your API key (
sk_live_.../sk_test_...) must never reach a browser — use this library from your own server only. Get your keys from the MyroPay business dashboard under API & Apps. - Amounts are in the currency's own whole units (e.g.
500000NGN = ₦500,000), not subunits like kobo or cents. - For a client-side "Pay with MyroPay" button/modal that never needs your secret key, use the Checkout SDK (
myropay.js) instead — this package is for server-side charge creation and verification.
Errors
use Myropay\Exception\ApiException; use Myropay\Exception\InvalidRequestException; try { \Myropay\Charge::create(['amount' => 5000]); // missing email } catch (InvalidRequestException $e) { // missing/invalid parameters, no request was sent } catch (ApiException $e) { // the API itself returned an error echo $e->getMessage() . ' (HTTP ' . $e->getHttpStatus() . ')'; }
License
MIT