Okay, so I am trying to find out if the transaction id of a payment is unique in the DB or not. How do I do this in a controller? I know the CUniqueValidator exists but am lost on how to use it in a controller.
What is the alternative?
Here is my code so far-
/**
* IPN notification action
*/
public function actionPaymentNotify()
{
// No layout.. this is just an action for payment notification
$this->layout = false;
switch($_GET['service'])
{
case Invoice::PAYMENT_PAYPAL:
$paypal = new Paypal();
// Log the IPN results
// $paypal->ipnLog = TRUE;
// Enable test mode if debugging is on
defined('YII_DEBUG')&&YII_DEBUG==true ? $paypal->enableTestMode() : null;
// Check validity
if ($paypal->validateIpn())
{
if ($paypal->ipnData['payment_status'] == 'Completed')
{
$model = Invoice::model()->findByPk($paypal->ipnData['item_number']);
// Want the validation in this if
if($paypal->ipnData['receiver_email'] == Yii::app()->params['paypalEmail']
&& $paypal->ipnData['payment_amount'] == $model->amount
&& $paypal->ipnData['currency_code'] == Yii::app()->params['currencyCode'])
{
$model->paid = 1;
$model->transactionID = $paypal->ipnData['txn_id'];
$model->paymentGateway = Invoice::PAYMENT_PAYPAL;
$model->save();
}
}
}
break;
}
}
Yeah, I sure do. I am using this in an open source project which is currently being coded (the controller above). Its in trunk/protected/components/payment_gateways in the SVN.