Search by

myropayme / myropay-php

myropayme

Official PHP library for the MyroPay API

Package info

github.com/myropayme/myropay-php

Homepage

pkg:composer/myropayme/myropay-php

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-07-13 12:09 UTC

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. 500000 NGN = ₦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