gintonicweb/payments

此包已被弃用且不再维护。未建议替代包。

CakePHP上支付网关的包装器

安装: 247

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 1

开放问题: 0

类型:cakephp-plugin

dev-master 2015-10-03 01:35 UTC

This package is not auto-updated.

Last update: 2017-05-06 12:48:19 UTC


README

Build Status Coverage Status

警告:请勿使用,处于非常早期阶段

thephpleague/Omnipay的包装器。将“可收费”行为附加到自己的模型上,以自动通过所选网关处理支付。

安装

使用 composer

composer require gintonicweb/payments:dev-master

bootstrap.php 中加载插件,如下所示

Plugin::load('Payments');

以下是可以添加到应用程序的 bootstrap.php 文件中的选项列表

Configure::write('Payments' => [
    'PayPal_Express' => [
        'username' => 'example_username',
        'password' => 'example_password',
        'signature' => 'example_signature',
        'testMode' => true,
    ],
    'Stripe' => [
        'apiKey' => 'example_key',
    ],
]);

将可收费行为附加到自己的 ItemsTable.php(或任何需要处理支付的表)中,如下所示。

$this->addBehavior('Payments.Chargeable', [
    'gateway' => 'PayPal_Express',
    'fields' => [
        'amount' => 'my_amount_field',
        'name' => 'my_name_field',
        'description' => 'my_description_field',
        'currency' => 'USD',
    ]
    'defaults' => [
        'amount' => '10.00',
        'name' => 'Generic Item Name',
        'description' => 'Generic Item description here',
        'currency' => 'USD',
    ]
]);

使用'fields'部分来映射数据库中的哪些字段用于交易。如果所有项目都使用相同的值(例如,对于货币),则可以跳过数据库查找并设置id作为默认选项。

使用方法

创建一个表单并收集信用卡信息。以下信用卡字段(以'pay-'开头)是必需的

  • card-number
  • card-expiry-month
  • card-expiry-year
  • card-cvc

还提供了一些额外的字段,可以将账单或运输信息添加到支付中。以下客户信息字段(以'pay-bill-'或'pay-ship-'开头)可用

  • firstName
  • lastName
  • company
  • address1
  • address2
  • city
  • postcode
  • state
  • country
  • phone
<?php $this->Form->create($item) ?>
    echo $this->Form->input('pay-bill-firstname', ['type' => 'text', 'label' => 'First Name']);
    echo $this->Form->input('pay-bill-lastname', ['type' => 'text', 'label' => 'Last Name']);
    echo $this->Form->input('pay-card-number', ['type' => 'text', 'label' => 'Card Number']);
    echo $this->Form->input('pay-card-expiry-month', ['type' => 'text', 'label' => 'Expiration Month']);
    echo $this->Form->input('pay-card-expiry-year', ['type' => 'text', 'label' => 'Expiration Year']);
    echo $this->Form->input('pay-card-cvc', ['type' => 'text', 'label' => 'CVC']);
<?php $this->Form->end() ?>

在实体上调用purchase()。

public function purchase($item_id)
{        
    $item = $this->Item->newEntity();
    if ($this->request->is('post')) {

        $user = $this->Auth->user();
        $this->request->data['user_id'] = $user['id'];
        $this->request->data['item_id'] = $item_id;

        // Create the requested charge
        $charge = $this->Items->purchase($user, $this->request->data);
        if ($charge) {
            $this->Flash->success('Purchase successful');
        } else {
            $this->Flash->error('Purchase error');
        }
    }
    $this->set(compact('item'));
}

$this->request->data 中传递的数据必须是以下内容

TODO