leodyversemilla07/paymongo-php
Composer 安装命令:
composer require leodyversemilla07/paymongo-php
包简介
PayMongo PHP SDK for payments, checkout, webhooks, subscriptions, refunds, and other API resources.
README 文档
README
A PHP SDK for integrating with the PayMongo API across payments, checkout, subscriptions, webhooks, transfers, issuing, and onboarding resources.
Features
- Broad PayMongo API coverage for currently implemented resources
- Payment Intents, Payment Methods, Payments, Refunds
- Checkout Sessions, Links
- QR Ph payments
- Subscriptions, Plans, Invoices
- Fraud Detection (Reviews, Rules, Scores)
- Wallets, Transfers, Ledgers
- Forex (Rates, Quotes)
- Card Issuing (Programs, Cardholders, Cards)
- Merchant Onboarding
- Webhook signature verification
- Idempotency support
Requirements
- PHP 8.2 or higher
- cURL extension
- JSON extension
- mbstring extension
Installation
Install via Composer:
composer require leodyversemilla07/paymongo-php
Quick Start
<?php require_once 'vendor/autoload.php'; use Paymongo\PaymongoClient; $client = new PaymongoClient('sk_test_your_secret_key'); // Create a payment intent $paymentIntent = $client->paymentIntents->create([ 'amount' => 10000, // Amount in cents (100.00 PHP) 'currency' => 'PHP', 'payment_method_allowed' => ['card', 'gcash', 'grab_pay'], 'description' => 'Order #12345', ]); echo $paymentIntent->id; echo $paymentIntent->client_key;
Usage Examples
Payment Intents
// Create a payment intent $paymentIntent = $client->paymentIntents->create([ 'amount' => 10000, 'currency' => 'PHP', 'payment_method_allowed' => ['card'], ]); // Retrieve a payment intent $paymentIntent = $client->paymentIntents->retrieve('pi_xxx'); // Attach a payment method to a payment intent $paymentIntent = $client->paymentIntents->attach('pi_xxx', [ 'payment_method' => 'pm_xxx', ]); // Capture a payment intent $paymentIntent = $client->paymentIntents->capture('pi_xxx', [ 'amount' => 10000, ]); // Cancel a payment intent $paymentIntent = $client->paymentIntents->cancel('pi_xxx');
Checkout Sessions
$checkoutSession = $client->checkoutSessions->create([ 'description' => 'Order #12345', 'line_items' => [ [ 'name' => 'Product Name', 'quantity' => 1, 'amount' => 10000, 'currency' => 'PHP', ], ], 'payment_method_types' => ['card', 'gcash', 'grab_pay'], 'success_url' => 'https://example.com/success', 'cancel_url' => 'https://example.com/cancel', ]); // Redirect user to checkout header('Location: ' . $checkoutSession->url);
Refunds
// Create a refund $refund = $client->refunds->create([ 'amount' => 5000, 'payment_id' => 'pay_xxx', 'reason' => 'requested_by_customer', ]); // List refunds $refunds = $client->refunds->all(['limit' => 10]);
Webhooks
// Create a webhook $webhook = $client->webhooks->create([ 'url' => 'https://example.com/webhooks/paymongo', 'events' => [ 'payment.paid', 'payment.failed', ], ]); // Verify webhook signature try { $payload = file_get_contents('php://input'); $signatureHeader = $_SERVER['HTTP_PAYMONGO_SIGNATURE']; $event = $client->webhooks->constructEvent([ 'payload' => $payload, 'signature_header' => $signatureHeader, 'webhook_secret_key' => 'whsec_xxx', ]); switch ($event->type) { case 'payment.paid': // Handle successful payment break; case 'payment.failed': // Handle failed payment break; } http_response_code(200); } catch (\Paymongo\Exceptions\SignatureVerificationException $e) { http_response_code(400); exit('Invalid signature'); }
Subscriptions
// Create a plan $plan = $client->plans->create([ 'name' => 'Premium Plan', 'amount' => 99900, 'currency' => 'PHP', 'interval' => 'month', ]); // Create a subscription $subscription = $client->subscriptions->create([ 'customer_id' => 'cus_xxx', 'plan_id' => 'plan_xxx', 'payment_method_id' => 'pm_xxx', ]); // Cancel a subscription $subscription = $client->subscriptions->cancel('sub_xxx');
Error Handling
use Paymongo\Exceptions\InvalidRequestException; use Paymongo\Exceptions\AuthenticationException; use Paymongo\Exceptions\ResourceNotFoundException; try { $paymentIntent = $client->paymentIntents->create([ 'amount' => 10000, 'currency' => 'PHP', 'payment_method_allowed' => ['card'], ]); } catch (AuthenticationException $e) { // Invalid API key echo 'Authentication failed: ' . $e->getMessage(); } catch (InvalidRequestException $e) { // Invalid parameters foreach ($e->getError() as $error) { echo $error->detail; } } catch (ResourceNotFoundException $e) { // Resource not found echo 'Resource not found'; }
Configuration
$client = new PaymongoClient('sk_test_xxx', [ 'timeout' => 30, 'connect_timeout' => 10, 'idempotency_key' => 'unique-request-id', ]);
For customersV2, you can provide a Bearer token when your integration uses PayMongo's JWT-based
customer authentication flow:
$client = new PaymongoClient('sk_test_xxx', [ 'customer_bearer_token' => 'jwt_customer_token', ]);
Available Services
| Service | Description |
|---|---|
paymentIntents |
Payment Intents API |
paymentMethods |
Payment Methods API |
payments |
Payments API |
refunds |
Refunds API |
customers |
Customers API (v1) |
customersV2 |
Customers API (v2, supports customer_bearer_token) |
checkoutSessions |
Checkout Sessions API |
links |
Payment Links API |
webhooks |
Webhooks API |
subscriptions |
Subscriptions API |
plans |
Plans API |
invoices |
Invoices API |
qrPh |
QR Ph API |
reviews |
Fraud Reviews API |
rules |
Fraud Rules API |
scores |
Fraud Scores API |
wallets |
Wallets API |
transfers |
Transfers API |
ledgers |
Ledgers API |
rates |
Forex Rates API |
quotes |
Forex Quotes API |
cards |
Card Issuing API |
cardPrograms |
Card Programs API |
cardholders |
Cardholders API |
workflows |
Workflows API |
policies |
Policies API |
Testing
composer test
Test Coverage Notes
- Unit tests validate request construction, entity hydration, and webhook signature handling.
- Integration-style tests use a fake HTTP client to verify service responses and error propagation.
Legacy APIs
sources remains available for legacy integrations, but PayMongo's current documentation recommends
using Payment Intents for new implementations.
customers maps to the older customer/card-vaulting surface, while customersV2 maps to the
current v2 customer endpoints. When using customersV2, set customer_bearer_token in the client
config if your integration follows PayMongo's JWT Bearer authentication flow for that API.
Not Yet Implemented
The current PayMongo documentation also includes newer product areas that are not yet covered by this SDK, including Platforms, Capital, Reconciliation, and Prism/Data surfaces.
Required vs Optional Fields
Entity constructors now validate required fields and throw Paymongo\Exceptions\UnexpectedValueException
when the API response is missing required attributes. Optional fields are safely defaulted to null.
Example:
use Paymongo\ApiResource; use Paymongo\Entities\PaymentIntent; use Paymongo\Exceptions\UnexpectedValueException; $resource = new ApiResource([ 'data' => [ 'id' => 'pi_test_123', 'attributes' => [ // 'amount' is missing here 'capture_type' => 'automatic', 'client_key' => 'pi_client_key', 'currency' => 'PHP', 'livemode' => false, 'status' => 'awaiting_payment_method', 'payment_method_allowed' => ['card'], 'created_at' => 0, 'updated_at' => 0, ], ], ]); try { new PaymentIntent($resource); } catch (UnexpectedValueException $e) { echo $e->getMessage(); }
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security-related issues, please email security@example.com instead of using the issue tracker.
Credits
License
MIT License. See LICENSE.
Resources
leodyversemilla07/paymongo-php 适用场景与选型建议
leodyversemilla07/paymongo-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「checkout」 「payments」 「sdk」 「payment processing」 「webhooks」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 leodyversemilla07/paymongo-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 leodyversemilla07/paymongo-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 leodyversemilla07/paymongo-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dealing with payments through the Egyptian payment gateway PayMob
Librería para la gestión sencilla de pagos mediante TPV Redsys y Paypal
A PSR-7 compatible library for making CRUD API endpoints
Adds a 'checkout' to a SilverStripe site which links to an Estimate and adds the ability to setup and pay
Rich payment solutions for Laravel framework. Paypal, payex, authorize.net, be2bill, omnipay, recurring paymens, instant notifications and many more
Add a simple webshop to your Laravel project
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-02