paymongo / paymongo-php
PayMongo PHP Library
Installs: 4 425
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 7
Forks: 9
Open Issues: 4
Requires
- php: >=5.6.0
- ext-curl: *
- ext-json: *
- ext-mbstring: *
Requires (Dev)
- phpunit/phpunit: ^9.1
This package is not auto-updated.
Last update: 2025-07-03 15:41:07 UTC
README
PayMongo PHP library provides PHP applications an easy access to the PayMongo API. Explore various classes that can represent API resources on object instantiation. The goal of this library is simplify PayMongo integration with any PHP applications.
Check example.php see usage examples.
Pending Todos
- Unit Tests
- Code Cleanup and Improvements
Requirements
PHP 5.6.0 and later.
Composer
You can install the library via Composer. Run the following command:
composer require paymongo/paymongo-php
To use the bindings, use Composer's autoload:
require_once('vendor/autoload.php');
Manual Installation
If you prefer to manually install the library instead of using composer, you can download the latest release. Then, to use the bindings, include the initialize.php
file.
require_once('/path/to/paymongo-php/initialize.php');
Dependencies
The bindings require the following extensions in order to work properly:
If you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that the required extensions are available.
Getting Started
Simple usage looks like:
$client = new \Paymongo\PaymongoClient('sk_test_BQokikJOvBiI2HlWgH4b2fQ2'); $paymentIntent = $client->paymentIntents->create([ 'amount' => 10000, 'currency' => 'PHP', 'payment_method_allowed' => ['card'] ]); echo $paymentIntent->id;
Handle errors
try { $client = new \Paymongo\PaymongoClient('sk_test_BQokikJOvBiI2HlWgH4b2fQ2'); $paymentIntent = $client->paymentIntents->create([ 'amount' => 10000, 'currency' => 'PHP', 'payment_method_allowed' => ['card'] ]); } catch(\Paymongo\Exceptions\InvalidRequestException $e) { print "<pre>"; print_r($e->getError()); print "</pre>"; }
Verifying webhook signature
try { $payload = @file_get_contents('php://input'); $signatureHeader = $_SERVER['HTTP_PAYMONGO_SIGNATURE']; $webhookSecretKey = 'your webhook secret key here'; $event = $client->webhooks->constructEvent([ 'payload' => $payload, 'signature_header' => $signatureHeader, 'webhook_secret_key' => $webhookSecretKey ]); echo $event->id; echo $event->type; print "<pre>"; print_r($event->resource); print "</pre>"; die(); } catch (\Paymongo\Exceptions\SignatureVerificationException $e) { echo 'invalid signature'; }
To learn more about PayMongo's API, please check our developer documentation.