承接 cmpayments/payments-sdk-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

cmpayments/payments-sdk-php

Composer 安装命令:

composer require cmpayments/payments-sdk-php

包简介

SDK that makes it easy to connect to the CMPayments payment API

README 文档

README

Build Status Scrutinizer Coverage Software License Total Downloads

Integrating the CMPayments solutions for online payments with your application is easy using the Payment SDK for PHP.

Installation

To install the SDK, simply use Composer: composer require cmpayments/payments-sdk-php

Requirements

  • PHP 5.5+
  • PHP cURL extension
  • Up to date SSL, capable of TLS 1.0 or higher

Dependencies

  • MoneyPHP is used to encapsulate sums of money and their currency
  • Guzzle is used to make HTTP requests

These are automatically installed by composer.

Bootstrapping

To do anything with the SDK, the first step is to create an instance of the payment Gateway:

<?php
use CMPayments\PaymentSdk\Credentials;
use CMPayments\PaymentSdk\Gateway;

$gateway = new Gateway(new Credentials('your-api-key', 'your-api-secret'));

List iDEAL issuers

To get a list of iDEAL issuers, simply tell the Gateway to execute the IdealIssuerListRequest:

<?php
use CMPayments\PaymentSdk\Requests\IdealIssuerListRequest;

$issuers = $gateway->execute(new IdealIssuerListRequest());

foreach ($issuers as $name => $id) {
    // $name is now 'ABN AMRO Bank', 'Rabobank', 'ING', etc.
    // $id is now 'ABNANL2A', 'RABONL2U', 'INGBNL2A', etc.
}

Start a payment

The CMPayments API supports the concept of a Charge that contains 0..n Payment items underneath it. To start a payment, both a Charge and a Payment must be created. This can be done in one request:

<?php
use CMPayments\PaymentSdk\Entities\Charge;
use CMPayments\PaymentSdk\Entities\IdealPayment;
use CMPayments\PaymentSdk\Requests\CreateChargeRequest;
use Money\Money;

//  Create both a charge and a payment object
$payment = new IdealPayment(Money::EUR(500), 'RABONL2U', 'your-unique-purchase-id', 'A description of the transaction');
$charge = new Charge(Money::EUR(500), [$payment]);

$response = $gateway->execute(new CreateChargeRequest($charge));

//  The id of the charge is available as $response->charge_id, the id of the payment in $response->payments[0]->payment_id
//  These ids are in the form of ch- (or charge) or pt- (for payment), followed by a uuid v4.
//  To have the user complete the payment, redirect them to $response->payments[0]->payment_details->authentication_url

Note: Each payment method has its own {METHOD}Payment class. Each of these classes enforces all required properties trough their constructors. For instance, to create a new CreditCard payment, replace the new IdealPayment(...) line with new CreditCardPayment(Money::EUR(500), ['VISA', 'MasterCard'], 'your-purchase-id', new \DateTime('+1 day'));.

Retreive charge or a payment

Simple tell the Gateway to execute a ViewChargeRequest of ViewPaymentRequest with the correct id, and the details will be retrieved.

<?php
use CMPayments\PaymentSdk\Requests\ViewChargeRequest;
use CMPayments\PaymentSdk\Requests\ViewPaymentRequest;

$response = $gateway->execute(
    new ViewChargeRequest('ch-fd0e1e2d-f994-4afc-a0b6-f7e76550fc31')
);
$response = $gateway->execute(
    new ViewPaymentRequest('pt-297bba0f-5fae-4ec2-8c0f-dfbc0f62f6b0')
);

Handling errors

Internally, Guzzle is used to make HTTP requests. When the API responds with a 4xx or 5xx HTTP status, either a ClientException or a ServerException is thrown.

In case of a ServerException, the CMPayments platform is having issues. Try the request again later.

For a ClientException, check $exception->getResponse()->getBody()->getContents() to see what is wrong.

Working with Money

The Money library in use requires that any amount is represented in the smallest unig (eg. cents), so EUR 5,- is written as new Money(500, new Currency('EUR')) or shorter as Money::EUR(500).

Because this can be a bit of a hassle, the MoneyConverter class is provided. It can convert a float + currency into a Money object and back.

<?php
use \CMPayments\PaymentSdk\MoneyConverter;
$converter = new MoneyConverter();

$money = $converter->fromAmountAndCurrency(5.00, 'EUR');

$amount = $converter->toFloat($money);

cmpayments/payments-sdk-php 适用场景与选型建议

cmpayments/payments-sdk-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.11k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2017 年 11 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 cmpayments/payments-sdk-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 cmpayments/payments-sdk-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 cmpayments/payments-sdk-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 0
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-11-07