Paypal PayFlow API Wrapper Class
The Paypal Payflow Payment Gateway can help you accept credit card payments quickly and affordably. Over 32% of US online business runs through PayPal’s Payflow payment gateway. They provide a reliable, secure connection trusted by business, banks, and online shoppers. No long-term commitments or monthly minimums.
What can I do with it?
This class is a wrapper to the Payflow API written in PHP5 that can be used to submit credit card transactions to the Payflow payment gateway. The class provides functions for setting the payment details like the customer name, address, phone number, shipping address, charge amount, credit card number and expiry date.
A function is also provided to add additional custom fields to the API call.
How do I use it?
The first thing you'll want to do is create a Paypal Payflow Sandbox Account for testing purposes. Fork the class on Github and plugin in the information that you want to submit. An example is shown below:
Sending a Single Transaction to Paypal
<?php
require_once('Class.PayFlow.php');
/**
* Create new Single Transaction.
*/
$PayFlow = new PayFlow('VENDOR', 'PARTNER', 'USER', 'PASSWORD', 'single');
$PayFlow->setEnvironment('test');
$PayFlow->setTransactionType('S');
$PayFlow->setPaymentMethod('C');
$PayFlow->setPaymentCurrency('USD');
$PayFlow->setAmount('15.00', FALSE);
$PayFlow->setCCNumber('378282246310005');
$PayFlow->setCVV('4685');
$PayFlow->setExpiration('1112');
$PayFlow->setCreditCardName('Richard Castera');
$PayFlow->setCustomerFirstName('Richard');
$PayFlow->setCustomerLastName('Castera');
$PayFlow->setCustomerAddress('589 8th Ave Suite 10');
$PayFlow->setCustomerCity('New York');
$PayFlow->setCustomerState('NY');
$PayFlow->setCustomerZip('10018');
$PayFlow->setCustomerCountry('US');
$PayFlow->setCustomerPhone('212-123-1234');
$PayFlow->setCustomerEmail('richard.castera@gmail.com');
$PayFlow->setPaymentComment('New Regular Transaction');
$PayFlow->setPaymentComment2('Product 233');
if($PayFlow->processTransaction()):
echo('Transaction Processed Successfully!');
else:
echo('Transaction could not be processed at this time.');
endif;
echo('<h2>Name Value Pair String:</h2>');
echo('<pre>');
print_r($PayFlow->debugNVP('array'));
echo('</pre>');
echo('<h2>Response From Paypal:</h2>');
echo('<pre>');
print_r($PayFlow->getResponse());
echo('</pre>');
unset($PayFlow);
?>
Sending a Recurring Transaction to Paypal
<?php
require_once('Class.PayFlow.php');
/**
* Create new Recurring Transaction.
*/
$PayFlow = new PayFlow('VENDOR', 'PARTNER', 'USER', 'PASSWORD', 'recurring');
$PayFlow->setEnvironment('test');
$PayFlow->setTransactionType('R');
$PayFlow->setPaymentMethod('C');
$PayFlow->setPaymentCurrency('USD');
// Only used for recurring transactions
$PayFlow->setProfileAction('A');
$PayFlow->setProfileName('Richard_Castera');
$PayFlow->setProfileStartDate(date('mdY', strtotime("+1 day")));
$PayFlow->setProfilePayPeriod('MONT');
$PayFlow->setProfileTerm(0);
$PayFlow->setAmount('15.00', FALSE);
$PayFlow->setCCNumber('378282246310005');
$PayFlow->setCVV('4685');
$PayFlow->setExpiration('1112');
$PayFlow->setCreditCardName('Richard Castera');
$PayFlow->setCustomerFirstName('Richard');
$PayFlow->setCustomerLastName('Castera');
$PayFlow->setCustomerAddress('589 8th Ave Suite 10');
$PayFlow->setCustomerCity('New York');
$PayFlow->setCustomerState('NY');
$PayFlow->setCustomerZip('10018');
$PayFlow->setCustomerCountry('US');
$PayFlow->setCustomerPhone('212-123-1234');
$PayFlow->setCustomerEmail('richard.castera@gmail.com');
$PayFlow->setPaymentComment('New Regular Transaction');
if($PayFlow->processTransaction()):
echo('Transaction Processed Successfully!');
else:
echo('Transaction could not be processed at this time.');
endif;
echo('<h2>Name Value Pair String:</h2>');
echo('<pre>');
print_r($PayFlow->debugNVP('array'));
echo('</pre>');
echo('<h2>Response From Paypal:</h2>');
echo('<pre>');
print_r($PayFlow->getResponse());
echo('</pre>');
unset($PayFlow);
?>
</pre>
