CODE EXAMPLES:
The examples below show how to call PayKit.
Example #1:
// initialize variables
$payFlow = new PK_PayFlow();
$PK = new PK();
$PFP = new PK_PayFlowProfile();
$pkData = $PK->emptyObject();
$pkData->email = 'email@account.com';
$pkData->trxtype = 'S';
$pkData->action = 'A';
$pkData->tender = 'C';
$pkData->acct = '1234123412341234'; // credit card number
$pkData->cvv2 = '555'; // security code
$pkData->expdate = '1010'; // MMYY
$pkData->firstname = 'Demo';
$pkData->middlename = '';
$pkData->lastname = 'Customer';
$pkData->street = '1 Any Street';
$pkData->city = 'New York';
$pkData->state = 'NY';
$pkData->zip = '10024';
$pkData->currency = 'USD';
$pkData->country = 'US';
$pkData->clientip = $_SERVER['REMOTE_ADDR'];
$pkData->amt = '1.00';
$pkData->comment1 = "PayKit Demo";
$success = $payFlow->doPayment($pkData);
doPayment creates a formed cURL request, sends the request to the PayPal PayFlow Pro payment gateway, and records PayFlow Pro’s response (either an authorization number or an error message).
The above example handles a one-time payment. With just a few changes, you can set up a subscription (recurring) payment, use a trial period, or set up a payment installment plan.
Example #2:
$pkData->trxtype = 'R'; changed from 'S' to 'R'
begin additional code
$pkData->maxfailpayments = 3;
// # of failed payments before canceling subscription
$pkData->retrynumdays = 3;
// # of days to retry a failed authorization
$pkData->start = '01012009';
// date when first charge will occur: MMDDYYYY
$pkData->term = 0;
// # of subscription periods: use 0 for perpetual
$pkData->payperiod = 'MONT';
// subscription period
$pkData->profilename = 'profile_0123456789';
end additional code
$success = $payFlow->recurringTransaction($pkData);
changed from doPayment to recurringTransaction
To test this in action, you can view our Live Demo!
In addition to the functions doPayment performs, recurringTransaction creates a profile in PayPal PayFlow Pro that will be charged according to schedule. This profile keeps all payment history.