payplug/payplug-php

一个简单的PHP库,用于PayPlug公共API。

3.5.6 2015-05-06 00:00 UTC

README

Payplug API的PHP库

CI Status Packagist

这是Payplug PHP库的文档。它旨在帮助开发人员以简单、稳健的方式将Payplug用作支付解决方案。

您可以在https://www.payplug.com/创建Payplug账户。

维护

CA证书(cacert.pem)应每年在12月的第一周更新。请访问https://curl.se/docs/caextract.html获取最新的证书。

先决条件

Payplug的库依赖于cURL执行HTTP请求,并需要OpenSSL (1.0.1或更新版本)来确保交易的安全。您还需要PHP 5.3或更新版本用于Payplug PHP V2。

对于PHP 5.2或更早版本,您必须参考Payplug PHP V1。

文档

请参阅https://docs.payplug.com/api获取最新的文档。

安装

选项1 - 强烈推荐) 通过composer

  • composer网站获取composer。
  • 确保您已初始化您的composer.json
  • 在您的项目目录中运行composer require payplug/payplug-php

选项2- 克隆仓库

git clone https://github.com/payplug/payplug-php.git

选项3) 下载tar包

  • 下载页面V2(V2适用于PHP 5.3或更新版本)下载最新的tar包
  • 下载页面V1(V1适用于PHP 5.2或更早版本)下载最新的tar包
  • 解压tar包
  • 将文件放置在您的项目中某个位置

要开始,请将以下内容添加到您的PHP脚本中(如果您没有运行框架)

<?php
require_once("PATH_TO_PAYPLUG/payplug_php/lib/init.php");

项目Git工作流程

此仓库遵循特定的Git工作流程以确保协作顺利和版本控制。请按照以下步骤参与此项目。

Git工作流程步骤

  1. 创建功能或修复分支

    在做出任何更改之前,从develop分支创建一个新的分支

    git checkout develop
    git pull origin develop
    git checkout -b <feature-name>
    

    对于修复错误,使用

    git checkout develop
    git pull origin develop
    git checkout -b <fix-name>
    
  2. 工作于您的功能或修复

    进行代码更改并将它们提交到您的功能或修复分支。

  3. 创建合并请求

    一旦您的功能或修复准备就绪,从您的分支创建到develop分支的合并请求。请您的同伴对您的更改进行审查。

  4. 发布准备

    在发布时间,从develop分支创建一个名为release-的中间分支

    git checkout develop
    git pull origin develop
    git checkout -b release-<version-number>
    
  5. 完成发布

    在release-分支上彻底测试代码。修复出现的任何错误或问题。

  6. 合并到master

    一旦发布经过测试且稳定,从release-分支创建到master分支的合并请求。这表示发布成功。

  7. 标记发布

    合并到master后,创建一个新的标签来标记发布版本

    git checkout master
    git pull origin master
    git tag -a v<version-number> -m "Release <version-number>"
    git push origin master --tags
    

用法

创建付款请求就这么简单

<?php
require_once("PATH_TO_PAYPLUG/payplug_php/lib/init.php"); // If not using a framework

// Loads your account's parameters that you've previously downloaded and saved
Payplug\Payplug::init(array(
  'secretKey' => 'sk_live_YOUR_PRIVATE_KEY',
  'apiVersion' => 'THE_API_VERSION_YOU_WANT',
));

// Create a payment request of €9.99. The payment confirmation (IPN) will be sent to "'https://example.net/notifications?id='.$customer_id".
// Note that all amounts must be expressed in centimes as positive whole numbers (€9.99 = 999 centimes).
// Metadata allow you to include additional information when processing payments or refunds.
$customer_id = '42710';

$payment = Payplug\Payment::create(array(
        'amount'            => 999,
        'currency'          => 'EUR',
        'billing'          => array(
            'title'        => 'mr',
            'first_name'   => 'John',
            'last_name'    => 'Watson',
            'email'        => 'john.watson@example.net',
            'address1'     => '221B Baker Street',
            'postcode'     => 'NW16XE',
            'city'         => 'London',
            'country'      => 'GB',
            'language'     => 'en'
        ),
        'shipping'          => array(
            'title'         => 'mr',
            'first_name'    => 'John',
            'last_name'     => 'Watson',
            'email'         => 'john.watson@example.net',
            'address1'      => '221B Baker Street',
            'postcode'      => 'NW16XE',
            'city'          => 'London',
            'country'       => 'GB',
            'language'      => 'en',
            'delivery_type' => 'BILLING'
        ),
        'hosted_payment' => array(
            'return_url' => 'https://example.net/return?id='.$customer_id,
            'cancel_url' => 'https://example.net/cancel?id='.$customer_id
        ),
        'notification_url' => 'https://example.net/notifications?id='.$customer_id,
        'metadata'         => array(
            'customer_id'  => $customer_id
        )
));

// You will be able to find how the payment object is built in the documentation.
// For instance, if you want to get a URL to the payment page, you can do:
$paymentUrl = $payment->hosted_payment->payment_url;

// Then, you can redirect the user to the payment page
header("Location: $paymentUrl");

更进一步

测试

查看tests/README.rst。

项目负责人

本项目由以下人员维护:

关于工作流程的任何问题或担忧,请随时联系项目负责人。