univicosa/laravel-payment-client

2.2.1 2020-03-04 12:19 UTC

This package is auto-updated.

Last update: 2024-09-17 00:58:15 UTC


README

univicosa/laravel-payment-client 是一个 Laravel 包,用于将支付服务器集成到需要支付请求的 Laravel 项目中。

安装

使用 composer 安装

composer require univicosa/laravel-payment-client

对于版本小于 5.5 的 Laravel,请在 config/app.php 中添加服务提供者

Modules\OpenId\Providers\OpenIdServiceProvider::class

在您的 .env 文件中定义系统,设置环境变量

SYSTEM_ID 是由管理服务器为您系统生成的,SYSTEM_PASSWORD 是由管理服务器为您系统生成的,PAYMENT_SERVER 根据您使用的环境进行定义

为了个性化配置,通过运行以下命令发布包的配置文件:

php artisan vendor:publish --tag=payment

将生成 config/openid.php 文件。

注意:您的系统需要通过支付管理服务授权,并使用 OpenId 客户端来验证请求支付的用户。

创建新账户

为了进行支付请求,客户端需要使用有效的收款人。要按需创建一个,只需实现 Payment::createBeneficiary() 方法,并遵循以下规则:

请求体

{
  "name" : "bail|required|string|min:5",
  "system" : "bail|required|string|size:24",
  "account" : "bail|required|string",
  "valid_until" : "bail|required|date|after:now"
}

内容说明

'name'        => 'The name that describes your beneficiary in the report list',
'system'      => 'The id that the Payment server admin provides to you',
'account'     => 'The bank account that Payment server admin provides to you',
'valid_until' => 'The final date your account will accepts payments requests'

支付请求

要通过 API 客户端向服务器请求支付,您应该实例化可用的类型之一,并通过 \Payment::send() Facade 将其传递给驱动程序。驱动程序将识别您的支付实例并将其发送到适当的端点。

请求接受 N 个项目,使得客户端可以使用一个购物车中的项目在单个支付实例中完成支付。

支付请求应遵循所有支付实例的规则。所有可用的类型都将扩展

请求体

{
  "payer": {
    "name" : "bail|required|string|min:3",
    "email" : "bail|required|string|min:5",
    "address" : "bail|required|string|min:3",
    "district" : "bail|required|string|min:2",
    "number" : "bail|required|string|min:1",
    "cep" : "bail|required|string|min:8|max:9|cep",
    "state" : "bail|required|string|min:2",
    "city" : "bail|required|string|min:3",
    "cpf" : "bail|required|string|size:11|cpf"
  },
  "value" : "bail|required|numeric|min:0",
  "operator" : "bail|required|string",
  "items" : [
      {
        "name" : "bail|required|string|min:3",
        "amount" : "bail|required|numeric|min:0",
        "discount_amount" : "bail|required|numeric|min:0",
        "final_value" : "bail|required|numeric|min:0",
        "discounts" : [
          {
            "*" : "bail|filled|array|min:1"
          }
        ],
        "beneficiary" : "bail|required|string|size:24",
        "details" : [
          {
            "item" : "bail|required|string|min:3",
            "value" : "bail|required|numeric|min:0"
          }  
        ]
      }
    ]
}

内容说明

'operator' => 'the financier operator of your transaction. EX: SICOOB, Cielo'

可用的支付类型

以下所有类型都将扩展 Payment 类的默认规则。

票据

所有当前的票据支付只接受 SICOOB 运营商,退货方法都是手动操作。支付通知是在此之后做出的,并且可以等待 72 小时的银行退货。

请求体

{
  "descriptions" : [
    {
      "description" : "bail|required|string|min:5"
    }
  ],
  "deadline" : "bail|required|integer|min:0"
}

内容说明

'descriptions' => 'add the descriptions to boleto's document body, max 4'

注意:如果截止日期识别的最后日期为一个非工作日,则截止日期将是下一个星期一。

信用卡

所有当前的信用卡支付接受 Visa、Mastercard、American Express、ELO、Diners 和 Amex 品牌的信用卡。

请求体

{
  "credit_card" : {
    "token" : "bail|required"
  },
  "installments" : "bail|required|integer|min:1|max:6"
}

免费

免费支付是一个实例,它接受以 100% 折扣生成的免费用请求(包括优惠券),并且只需扩展默认规则,并需要接收 'value' 键为零。

内容说明

'value' => 'bail|required|numeric|min:0|max:0'

面对面支付

面对面支付是由授权用户在管理员面板下进行的,接受现金(类型 => 'money')或通过刷卡机(类型 => 'credit_card' 和类型 => 'debit_card')支付,并排除以下父规则:'payer.address'、'payer.district'、'payer.cep'、'payer.state' 和 'payer.city'。

请求体

{
  "presential" : {
    "type" : "bail|required|string",
    "installments" : "bail|required|integer|min:1",
    "token" : "bail|required",
    "responsible" : {
      "name" : "bail|required|string|min:3",
      "email" : "bail|required|string|email",
      "cpf" : "bail|required|string|size:11|cpf"
    }
  }
}

支付状态

每种支付类型都有特定的状态更新行,但它们都将遵守以下规则

已支付或计划接收的支付将获得 'payed' 状态。已取消、退款或关闭的支付将获得 'canceled' 状态。已中止或拒绝的支付将获得 'denied' 状态。所有其他可能的状态都转换为 'waiting' 状态。

'payed'、'canceled' 和 'denied' 状态是端点,在更新后不接收新的通知。

支付推送通知

该驱动实现了 /api/payment 路由,用于接收支付服务器发送的支付状态变更推送通知。通知中包含支付ID和更新后的状态。

需要定义处理返回的方法和控制器,这些定义应在已发布的 config/payment.php 文件中。

支付退款

可以使用门面 \Payment::cancel() 来退款。此方法需要一个支付ID作为参数,并将在支付服务器中调用取消过程。

使用信用卡进行的支付将在客户的发票中直接生成退款。

使用支票进行的支付并将支付完成时,将生成以付款人名义的退款,并且此过程需要根据IES内部规则由财务操作员内部处理。

门面

@method \Payment::createBeneficiary(Beneficiary $beneficiary): array
@api POST '/api/{version}/beneficiary'

@return array with the response of Post action
@method \Payment::send(\JsonSerializable $payment): array
@api POST '/api/{version}/{paymentType}'

@return array with the response of Post action
@method \Payment::getPayer(): array
@api GET '/api/{version}/user'

@return array with data of loged user
@method \Payment::cancel(string $type, string $id): array
@api DELETE '/api/{version}/{PaymentType}/{paymentId}'

@return array with the response of Delete action
@method \Payment::cancelItem(string $type, string $id, array $data, bool $cancel): array
@api DELETE '/api/{version}/{PaymentType}/item/{paymentId}'

@return array with the response of Delete action