Here's my solution (might not be best) for integrating Paypal Pro with Kohana.
Paypal
Create a Website Payments Pro account (https://developer.paypal.com/) and a buyer account.
Login to your business account (https://www.sandbox.paypal.com) and do the validation step (email, bank account). It's not clear, so i will take the time to specify this, paypal will not send the validation email to your real email, instead go to https://developer.paypal.com/ -> Test Email. Now go to "Profile" -> "API Access" -> "Request API Credentials" -> you want the API Signature, not the certificate (well in my case). You want to keep somewhere:
API Username:
API Password:
Signature:
Kohana
cp system/config/payment.php application/config
cp system/config/credit_cards.php application/config
Edit application/config/payment.php like so:
'SANDBOX_USER' => 'your API info',
'SANDBOX_PWD' => 'your API info',
'SANDBOX_SIGNATURE' => 'your API info',
Remove all other $config, only keeping PaypalPro.
Time to play with the driver:
mkdir -p application/libraries/drivers/Payment
cp modules/payment/libraries/drivers/Payment/Paypalpro.php application/libraries/drivers/Payment
Edit application/libraries/drivers/Payment/Paypalpro.php like so:
public function process()
{
// Check for required fields
/*
if (in_array(FALSE, $this->required_fields))
{
$fields = array();
foreach ($this->required_fields as $key => $field)
{
if (!$field) $fields[] = $key;
}
throw new Kohana_Exception('payment.required', implode(', ', $fields));
}
*/
...
return ($nvp_res_array);
I commented the "Check for required fields", because the required fields depends on the method (for example SetCustomerBillingAgreement doesn't required IPADDRESS). Also i am returning the response array instead of a bool (Success or Fail) so that we can deal with the response in a controller.
DoDirectPayment example controller
<?php defined('SYSPATH') or die('No direct script access.');
class Paypal_Controller extends Controller {
function __construct()
{
parent::__construct();
$this->paypal = new Payment('paypalpro');
}
function index()
{
$this->paypal->METHOD = 'DoDirectPayment';
$this->paypal->PAYMENTACTION = 'Sale';
$this->paypal->AMT = 5;
$this->paypal->IPADDRESS = '72.44.33.22';
$this->paypal->FIRSTNAME = 'Patrick';
$this->paypal->LASTNAME = 'Sebastien';
$this->paypal->CREDITCARDTYPE = 'Visa';
$this->paypal->ACCT = 'Use your buyer cc';
$this->paypal->EXPDATE = 'Use your buyer ccexp';
$this->paypal->CVV2 = '123';
$paypalresponse = $this->paypal->process();
print Kohana::debug($paypalresponse);
if($paypalresponse['ACK'] == 'Success') {
exit('Thank you for your money');
} else {
exit('big problem');
}
}
}
SetExpressCheckout example controller
<?php defined('SYSPATH') or die('No direct script access.');
class Paypal_Controller extends Controller {
function __construct()
{
parent::__construct();
$this->paypal = new Payment('paypalpro');
}
function index()
{
//PAYMENT - EXPRESSCHECKOUT
$this->paypal->METHOD = 'SetExpressCheckout';
$this->paypal->AMT = '6.00';
$this->paypal->CURRENCYCODE = 'CAD';
$this->paypal->RETURNURL = 'http://192.168.2.10/odd1/site/index.php/paypal/success';
$this->paypal->CANCELURL = 'http://192.168.2.10/odd1/site/index.php/paypal/cancel';
$paypalresponse = $this->paypal->process();
print Kohana::debug($paypalresponse);
if($paypalresponse['ACK'] == 'Success') {
url::redirect('https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='.$paypalresponse['TOKEN']);
} else {
exit('big problem');
}
}
function cancel()
{
exit('cancel');
}
function success()
{
$this->paypal->METHOD = 'DoExpressCheckoutPayment';
$this->paypal->PAYMENTACTION = 'Sale';
$this->paypal->PAYERID = $_GET['PayerID'];
$this->paypal->TOKEN = $_GET['token'];
$this->paypal->AMT = '6.00';
$this->paypal->CURRENCYCODE = 'CAD';
$paypalresponse = $this->paypal->process();
print Kohana::debug($paypalresponse);
if($paypalresponse['ACK'] == 'Success') {
exit('Thank you for your money!');
} else {
exit('big problem');
}
}
}
Recurring payment with Paypal Pro and Kohana
CreateRecurringPaymentsProfile
<?php defined('SYSPATH') or die('No direct script access.');
class Paypal_Controller extends Controller {
function __construct()
{
parent::__construct();
$this->paypal = new Payment('paypalpro');
}
function index()
{
$this->paypal->METHOD = 'CreateRecurringPaymentsProfile';
$this->paypal->CREDITCARDTYPE = 'Visa';
$this->paypal->ACCT = 'Your buyer cc';
$this->paypal->EXPDATE = 'Your buyer ccexp';
$this->paypal->FIRSTNAME = 'Patrick';
$this->paypal->LASTNAME = 'Sebastien';
$this->paypal->EMAIL = 'patrick@sebastien.com';
$this->paypal->PROFILESTARTDATE = '2009-04-02T14:04:00Z';
$this->paypal->CVV2 = '123';
$this->paypal->BILLINGPERIOD = 'Month';
$this->paypal->BILLINGFREQUENCY = '1';
$this->paypal->AMT = '6.00';
$this->paypal->CURRENCYCODE = 'CAD';
$this->paypal->VERSION = '54';
$this->paypal->DESC = 'I need money to eat';
$paypalresponse = $this->paypal->process();
print Kohana::debug($paypalresponse);
if($paypalresponse['ACK'] == 'Success') {
exit('Thank you for your money');
} else {
exit('big problem');
}
}
}
SetCustomerBillingAgreement
<?php defined('SYSPATH') or die('No direct script access.');
class Paypal_Controller extends Controller {
function __construct()
{
parent::__construct();
$this->paypal = new Payment('paypalpro');
}
function index()
{
//RECURRING PAYMENT - EXPRESSCHECKOUT
$this->paypal->METHOD = 'SetCustomerBillingAgreement';
$this->paypal->RETURNURL = 'http://192.168.2.10/odd1/site/index.php/paypal/success';
$this->paypal->CANCELURL = 'http://192.168.2.10/odd1/site/index.php/paypal/cancel';
$this->paypal->BILLINGTYPE = 'RecurringPayments';
$this->paypal->BILLINGAGREEMENTDESCRIPTION = 'ODDSociety';
$paypalresponse = $this->paypal->process();
print Kohana::debug($paypalresponse);
if($paypalresponse['ACK'] == 'Success') {
url::redirect('https://www.sandbox.paypal.com/webscr?cmd=_customer-billing-agreement&token='.$paypalresponse['TOKEN']);
} else {
exit('problem');
}
}
function cancel()
{
exit('cancel');
}
function success()
{
$this->paypal->METHOD = 'CreateRecurringPaymentsProfile';
$this->paypal->DESC = 'ODDSociety - paypal recurring';
$this->paypal->PROFILESTARTDATE = '2009-04-02T14:04:00Z';
$this->paypal->TOKEN = $_GET['token'];
$this->paypal->AMT = '19.86';
$this->paypal->CURRENCYCODE = 'CAD';
$this->paypal->BILLINGFREQUENCY = 1;
$this->paypal->BILLINGPERIOD = 'Month';
$paypalresponse = $this->paypal->process();
print Kohana::debug($paypalresponse);
if($paypalresponse['ACK'] == 'Success') {
exit('Success');
} else {
exit('problem');
}
}
}
Assume, I am a buyer and subscribed a newsletter for recurring period of 3 months with $ 7.95. Now I want to unsubscribe this newsletter option from the website.(Not through my paypal A/C).
What I have to do for recurring and cancel the recurring from the Buyer end?
Post preview:
Close preview