定制 siddik-web/unified-payment-gateway 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

siddik-web/unified-payment-gateway

Composer 安装命令:

composer require siddik-web/unified-payment-gateway

包简介

A unified payment gateway for PayPal and Stripe integrations in PHP

README 文档

README

Unified Payment Gateway is a PHP library that provides a unified interface for integrating both PayPal and Stripe payments. This package is designed with the SOLID principles in mind, making it modular, extendable, and easy to use in any PHP project.

Features

  • Unified API for handling payments across PayPal and Stripe.
  • Support for creating payments, capturing, and refunds.
  • Subscription management for both PayPal and Stripe.
  • Webhook handling for both PayPal and Stripe.
  • Easy configuration through a single config file.

Installation

Install the package using Composer:

composer require siddik-web/unified-payment-gateway

Configuration

To configure your payment providers, create a configuration file (e.g., config/payment_config.php) with the following structure:

<?php
return [
    'paypal' => [
        'client_id' => 'your_paypal_client_id',
        'client_secret' => 'your_paypal_secret',
        'sandbox' => true,  // Use 'production' for live environment
        'webhook_url' => 'https://example.com/paypal/webhook'
    ],
    'stripe' => [
        'api_key' => 'your_stripe_secret_key',
        'sandbox_api_key' => 'your_stripe_sandbox_secret_key',
        'webhook_secret' => 'your_stripe_webhook_secret',
        'sandbox' => true
    ],
    'default_provider' => 'stripe'  // or 'paypal'
];

Usage

Initialize the Unified Payment Client

To start using the library, create an instance of UnifiedPaymentClient through the UnifiedPaymentFactory.

use UnifiedPaymentGateway\UnifiedPaymentFactory;

$config = include 'config/payment_config.php';
$paymentClient = UnifiedPaymentFactory::createPaymentClient($config);

Creating a Payment

$paymentData = [
    'amount' => 5000,  // Amount in cents for Stripe (5000 = $50.00)
    'currency' => 'usd',
    'description' => 'Order #12345'
];

$response = $paymentClient->createPayment($paymentData);
echo "Payment created: " . json_encode($response);

Capturing a Payment

$paymentId = 'your_payment_id';
$response = $paymentClient->capturePayment($paymentId);
echo "Payment captured: " . json_encode($response);

Refunding a Payment

$refundData = [
    'amount' => 2000  // Amount to refund (optional)
];
$response = $paymentClient->refundPayment($paymentId, $refundData);
echo "Payment refunded: " . json_encode($response);

Managing Subscriptions

To create a subscription:

$subscriptionData = [
    'plan_id' => 'your_plan_id',
    'customer_id' => 'your_customer_id'
];

$response = $paymentClient->createSubscription($subscriptionData);
echo "Subscription created: " . json_encode($response);

Webhook Handling

To handle webhooks, use the handleWebhook method and pass in the webhook payload:

$webhookData = json_decode(file_get_contents('php://input'), true);
$response = $paymentClient->handleWebhook($webhookData);

Folder Structure

The main files and folders in this package include:

src/
├── PayPalApi/
├── StripeApi/
└── UnifiedPayment/
config/
└── payment_config.php  # Configuration file example
  • src/PayPalApi: Contains classes for managing PayPal-specific functionality.
  • src/StripeApi: Contains classes for managing Stripe-specific functionality.
  • src/UnifiedPayment: Contains classes for unified payment management.

Requirements

  • PHP 8.0 or higher
  • Composer
  • Guzzle for HTTP requests (automatically installed as a dependency)

License

This project is licensed under the MIT License.

Feel free to contribute, open issues, or request new features!

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-12