Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ActiveRecord storage and minor fixes #26

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
58 changes: 57 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,68 @@ Provide nice configuration layer, secured capture controller, storages and lots

## Resources

* [Documentation](http://payum.org/doc#PayumYiiExtension)
* [Documentation](http://payum.org/doc/0.15#PayumYiiExtension)
* [Forum](http://www.yiiframework.com/forum/index.php/topic/48571-payum-payment-extension/)
* [Sandbox](https://github.com/makasim/PayumYiiExtensionSandbox)
* [Questions](http://stackoverflow.com/questions/tagged/payum)
* [Issue Tracker](https://github.com/Payum/PayumYiiExtension/issues)

## DB storage
Use `migrations/add_payum_payment_tables.php` to add tables

```php
// app/config/main.php
use Payum\Core\Storage\FilesystemStorage;

$paypalExpressCheckoutPaymentFactory = new \Payum\Paypal\ExpressCheckout\Nvp\PaymentFactory();

return array(
'controllerMap'=>array(
'payment'=>array(
'class'=>'Payum\YiiExtension\PaymentController',
),
),
'components' => array(
'payum' => array(
'class' => '\Payum\YiiExtension\PayumComponent',
'tokenStorage' => new Payum\YiiExtension\Storage\CActiveRecordStorage('Payum\YiiExtension\Model\PaymentToken'),'PaymentSecurityToken', 'hash'),
'payments' => array(
// you can add other payments here.
'paypal_ec' => $paypalExpressCheckoutPaymentFactory->create(array(
'username' => 'EDIT ME',
'password' => 'EDIT ME',
'signature' => 'EDIT ME',
'sandbox' => true
)),
),
'storages' => array(
'Payum\YiiExtension\Model\PaymentDetails' => new Payum\YiiExtension\Storage\CActiveRecordStorage('Payum\YiiExtension\Model\PaymentDetails'),
)
),
),
);
```

```php
<?php
//app/controllers/PaypalController.php

class PaypalController extends CController
{
public function actionPrepare()
{
$paymentName = 'paypal_ec';

$payum = $this->getPayum();

$storage = $payum->getRegistry()->getStorage(
'Payum\YiiExtension\Model\PaymentDetails',
$paymentName
);
}
}
```

## Contributing

PayumYiiExtension is an open source, community-driven project. Pull requests are very welcome.
Expand Down
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"type": "yii-extension",
"description": "Rich payment solutions for Yii framework. Paypal, payex, authorize.net, be2bill, omnipay, recurring paymens, instant notifications and many more",
"keywords": [
"payment",
"paypal",
"be2bill",
"authorize.net",
"omnipay",
"paypal express checkout",
"paypal pro checkout",
"recurring payment",
"payment",
"paypal",
"be2bill",
"authorize.net",
"omnipay",
"paypal express checkout",
"paypal pro checkout",
"recurring payment",
"payex",
"offline",
"instant notification",
Expand Down Expand Up @@ -38,14 +38,14 @@
],
"require": {
"php": ">=5.3.2",
"payum/core": "0.15.*@dev"
"payum/core": "0.14.*"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The master is 1.0-dev

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm... it is not

},
"autoload": {
"psr-0": { "Payum\\YiiExtension": "" }
},
"extra": {
"branch-alias": {
"dev-master": "0.15-dev"
"dev-master": "0.14-dev"
}
},
"config": {
Expand Down
238 changes: 238 additions & 0 deletions src/Payum/YiiExtension/Model/PaymentDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
<?php

namespace Payum\YiiExtension\Model;

use Payum\Core\Model\PaymentInterface;

/**
* This is the model class for table "payum_payment_details".
*
* The followings are the available columns in table 'payum_payment_details':
*
* @property integer $id
* @property string $number
* @property string $description
* @property string $client_email
* @property string $client_id
* @property string $currency_code
* @property integer $total_amount
* @property integer $currency_digits_after_decimal_point
*
* The followings are the available model relations:
* @property PayumPaymentToken[] $payumPaymentTokens
*/
class PaymentDetails extends \CActiveRecord implements PaymentInterface
{
/**
* {@inheritDoc}
*/
public function init()
{
$this->setDetails(array());
$this->currency_digits_after_decimal_point = 2;
}

/**
* {@inheritDoc}
*/
public function primaryKey()
{
return 'id';
}

/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}

/**
* {@inheritDoc}
*/
public function getNumber()
{
return $this->number;
}

/**
* @param string $number
*/
public function setNumber($number)
{
$this->number = $number;
}

/**
* {@inheritDoc}
*/
public function getDescription()
{
return $this->description;
}

/**
* @param string $description
*/
public function setDescription($description)
{
$this->description = $description;
}

/**
* {@inheritDoc}
*/
public function getClientEmail()
{
return $this->client_email;
}

/**
* @param string $clientEmail
*/
public function setClientEmail($clientEmail)
{
$this->client_email = $clientEmail;
}

/**
* {@inheritDoc}
*/
public function getClientId()
{
return $this->client_id;
}

/**
* @param string $clientId
*/
public function setClientId($clientId)
{
$this->client_id = $clientId;
}

/**
* {@inheritDoc}
*/
public function getTotalAmount()
{
return $this->total_amount;
}

/**
* @param int $totalAmount
*/
public function setTotalAmount($totalAmount)
{
$this->total_amount = $totalAmount;
}

/**
* {@inheritDoc}
*/
public function getCurrencyCode()
{
return $this->currency_code;
}

/**
* @param string $currencyCode
* @param int $digitsAfterDecimalPoint
*/
public function setCurrencyCode($currencyCode, $digitsAfterDecimalPoint = 2)
{
$this->currency_code = $currencyCode;
$this->currency_digits_after_decimal_point = $digitsAfterDecimalPoint;
}

/**
* {@inheritDoc}
*/
public function getCurrencyDigitsAfterDecimalPoint()
{
return $this->currency_digits_after_decimal_point;
}

/**
* {@inheritDoc}
*/
public function getDetails()
{
if (null !== $this->details) {
return unserialize($this->details);
}
}

/**
* {@inheritDoc}
*
* @param array|\Traversable $details
*/
public function setDetails($details)
{
if ($details instanceof \Traversable) {
$details = iterator_to_array($details);
}

$this->details = serialize($details);
}

/**
* {@inheritDoc}
*/
public function tableName()
{
return 'payum_payment_details';
}

/**
* {@inheritDoc}
*/
public function rules()
{
return array(
array('number', 'required'),
array('total_amount, currency_digits_after_decimal_point', 'numerical', 'integerOnly' => true),
array('number, client_email, client_id, currency_code', 'length', 'max' => 255),
array('description', 'safe'),
);
}

/**
* {@inheritDoc}
*/
public function relations()
{
return array(
'payumPaymentTokens' => array(self::HAS_MANY, 'PayumPaymentToken', 'details_id'),
);
}

/**
* {@inheritDoc}
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'number' => 'Number',
'description' => 'Description',
'client_email' => 'Client Email',
'client_id' => 'Client',
'currency_code' => 'Currency Code',
'total_amount' => 'Total Amount',
'currency_digits_after_decimal_point' => 'Currency Digits After Decimal Point',
);
}

/**
* {@inheritDoc}
*/
public static function model($className = __CLASS__)
{
return parent::model($className);
}
}