fei/payment-common

该软件包最新版本(v2.6.0)没有提供许可证信息。

支付 - 公共组件

v2.6.0 2018-12-28 16:29 UTC

README

GitHub release

目录

实体

支付实体

除了传统的 idcreatedAt 字段外,支付实体还有十一个重要属性

  • uuid 是表示支付实体唯一标识符的字符串
  • createdAt 表示创建日期
  • payedAt 表示支付完成日期
  • expirationDate 表示支付过期日期
  • status 表示支付当前状态
  • cancellationReason 表示支付取消原因的字符串
  • requiredPrice 表示所需价格的浮点数
  • capturedPrice 表示已捕获价格的浮点数
  • authorizedPayment 是一个整数,表示已授权支付的列表(用作二进制标志)
  • selectedPayment 是一个整数,表示已选择的支付方式
  • contexts 是实体所有上下文的 ArrayCollection
  • callbackUrl 是回调 URL 数组,在应用的一些事件中将被使用(例如,当支付保存时)。以下是可能的值和回调 URL 的用途
    • succeeded : 当支付授权成功时将调用的 URL
    • failed : 当支付授权失败时将调用的 URL
    • cancelled : 当支付被取消时将调用的 URL

上下文实体

除了传统的 id 字段外,上下文实体有三个重要属性

  • key 是表示上下文键的字符串
  • value 是表示附加到此上下文的值的字符串
  • payment 是表示与该上下文相关的支付实体的支付实体

验证器

您可以使用 PaymentValidator 类验证 Payment 实体

<?php

use Fei\Service\Payment\Validator\PaymentValidator;
use Fei\Service\Payment\Entity\Payment;

$paymentValidator = new PaymentValidator('create');
$payment = new Payment();

//validate returns true if your Payment instance is valid, or false in the other case
$isPaymentValid = $paymentValidator->validate($payment);

//getErrors() allows you to get an array of errors if there are some, or an empty array in the other case
$errors = $paymentValidator->getErrors();

默认情况下,只有 uuidcreatedAtexpirationDatestatusrequiredPriceauthorizedPaymentcallbackUrl 属性不能为空,但您还可以使用 validate 方法仅验证实体的一些属性

<?php

use Fei\Service\Payment\Validator\PaymentValidator;
use Fei\Service\Payment\Entity\Payment;

$paymentValidator = new PaymentValidator('create');

$payment = new Payment();
$payment->setUuid('uuid');

$paymentValidator->validateUuid($payment->getUuid());

// will return an empty array : all of our definitions are correct
$errors = $paymentValidator->getErrors();
echo empty($errors); // true

// callbackUel can not be empty, let's try to set it as an empty string
$payment->setCallbackUrl([]);
$paymentValidator->validateCallbackUrl($payment->getCallbackUrl());

// this time you'll get a non-empty array
$errors = $paymentValidator->getErrors();

echo empty($errors); // false
print_r($errors);

/**
* print_r will return:
*
*    Array
*    (
*        ['callbackUrl'] => Array
*            (
*                'The callback URL cannot be empty'
*            )
*    )
**/

贡献

作为 OpCoding 设计和制作的 FEI 服务。贡献工作流程将涉及技术团队。欢迎贡献,改进功能和应用补丁,但请记住要仔细处理拉取请求。合并必须是 Flash 和 OpCoding 团队之间完全讨论的结果:)