gintonicweb / payments
Wrapper for payment gateways on CakePHP
Installs: 247
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Type:cakephp-plugin
Requires
- cakephp/cakephp: ~3.0
- omnipay/paypal: ~2.0
- omnipay/stripe: ~2.0
Requires (Dev)
This package is not auto-updated.
Last update: 2017-05-06 12:48:19 UTC
README
Warning: Do not use, very early stage
Wrapper for thephpleague/Omnipay. Attach the "chargeable" behavior to your own models to automaticly process the payments through the gateway of your choice.
Installation
Using composer.
composer require gintonicweb/payments:dev-master
Load the plugin in bootstrap.php
like:
Plugin::load('Payments');
Here's the list of options you can add to your applications' bootstrap.php
file
Configure::write('Payments' => [
'PayPal_Express' => [
'username' => 'example_username',
'password' => 'example_password',
'signature' => 'example_signature',
'testMode' => true,
],
'Stripe' => [
'apiKey' => 'example_key',
],
]);
Attach the chargeable behavior to your own ItemsTable.php
(or any table
requiring payments processing) like this.
$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',
]
]);
Use the 'fields' section to map which fields in your database to use for transactions. If all of the items use the same value, which is common for currency for example, you can skip the database lookup and set id as a default option.
Usage
Create a form and collect credit card information. The following credit card fields(prefixed with 'pay-') are required:
- card-number
- card-expiry-month
- card-expiry-year
- card-cvc
Some extra fields are also available to add billing or shipping information to a payment. The following customer information fields(prefixed with 'pay-bill-' or 'pay-ship-') are available:
- 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() ?>
Call purchase() on the entity.
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'));
}
The passed data in $this->request->data
must be the following
TODO