Angell EYE Solutions Specialists in eBay and PayPal Integration 2009-05-29T13:01:50Z WordPress http://www.angelleye.com/blog/feed/atom/ angelleye http://www.angelleye.com <![CDATA[Generate Microsoft Money, Quicken, Quickbooks QIF File from PayPal Account Transactions]]> http://www.angelleye.com/blog/?p=67 2009-05-29T13:01:50Z 2009-05-29T09:06:22Z I finally got annoyed enough with hand entering transactions into PayPal that I decided to throw together a basic QIF generator similar to what you get when you download transactions from a bank web site. PayPal’s exporting features just don’t do the trick in my opinion.

I used my NVP Class for PayPal so if you don’t have that already you’ll need it to use this script. Just make sure to add your API credentials into it.

This is very basic at the moment but it’s already saved me lots of time because it splits out the fees and sets the categories for them. It also adds the PayPal transaction ID to the notes of the imported transaction. You may want to add some of your own logic to set different categories based on the other transaction data. There’s a variable called $DaysBack that you can hard-code in the script or form post to so you can set how many days back you want to the script to grab transactions for.

I based this off a .qif I got from Bank of America so it should work pretty smoothly all-around. Let me know otherwise.

Download Zip File

<?php
require_once('paypal.nvp.class.php');

# Create PayPal object
$PayPalConfig = array('Sandbox' => $sandbox);
$PayPal = new PayPalPro($PayPalConfig);

# Generate Start/End Dates
$DaysBack = isset($_POST['DaysBack']) ? $_POST['DaysBack'] : 1;
$Timestamp = strtotime('now -' . $DaysBack . ' days');
$StartDate = gmdate('Y-m-d\TH:i:s.00\Z', $Timestamp);
$Timestamp = strtotime('now');
$EndDate = gmdate('Y-m-d\TH:i:s.00\Z', $Timestamp);

# Send request to PayPal APIv
$TSFields = array(
					'startdate' => $StartDate, 							// Required.  The earliest transaction date you want returned.  Must be in UTC/GMT format.  2008-08-30T05:00:00.00Z
					'enddate' => $EndDate, 								// The latest transaction date you want to be included.
					'status' => 'Success' 								// Search by transaction status.  Possible values: Pending, Processing, Success, Denied, Reversed
				);

$TransactionSearchData = array('TSFields' => $TSFields);
$TSResult = $PayPal -> TransactionSearch($TransactionSearchData);

# Display any errors returned from PayPal
$Errors = $TSResult['ERRORS'];
if(count($Errors) > 0)
{
	echo '<pre />';
	print_r($Errors);
}

# Store transactions in $Transactions
$Transactions = isset($TSResult['SEARCHRESULTS']) ? $TSResult['SEARCHRESULTS'] : array();

/*
Generate QIF file for MS Money

D 	Date
T 	Amount
C 	Cleared status
N 	Num (check or reference number)
P 	Payee
M 	Memo
A 	Address (up to five lines; the sixth line is an optional message)
L 	Category (Category/Subcategory/Transfer/Class)
S 	Category in split (Category/Transfer/Class)
E 	Memo in split
$ 	Dollar amount of split
^ 	End of entry
*/
$qif = '!Type:Bank' . chr(10);

foreach($Transactions as $index => $Transaction)
{
	$Timestamp = $Transaction['L_TIMESTAMP'];
	$Type = $Transaction['L_TYPE'];
	$Email = $Transaction['L_EMAIL'];
	$Name = $Transaction['L_NAME'];
	$TransactionID = $Transaction['L_TRANSACTIONID'];
	$Status = $Transaction['L_STATUS'];
	$Amt = $Transaction['L_AMT'];
	$FeeAmt = $Transaction['L_FEEAMT'];
	$NetAmt = $Transaction['L_NETAMT'];

	# Reformat Date
	$Date = substr($Timestamp, 0, 10);
	$DateSplit = explode('-',$Date);
	$DateYear = $DateSplit[0];
	$DateMo = $DateSplit[1];
	$DateDay = $DateSplit[2];
	$Date = $DateMo . '/' . $DateDay . '\'' . $DateYear;

	# You may want some logic here to set category and notes depending on the other transaction data.
	$Category = 'Sales Income';
	$Notes = 'PayPal Trans: ' . $TransactionID;

	# Add transaction
	$qif .= 'D' . $Date . chr(10) .
			'T' . $Amt . chr(10) .
			'CX' . chr(10) .
			'P' . $Name . chr(10) .
			'L' . $Category . chr(10) .
			'M' . $Notes . chr(10) .
			'^' . chr(10);

	# If a fee was included, add it separately.
	if($FeeAmt < 0)
	{
		$qif .= 'D' . $Date . chr(10) .
				'T' . $FeeAmt . chr(10) .
				'CX' . chr(10) .
				'PPayPal' . chr(10) .
				'LPayPal Fee' . chr(10) .
				'MPayPal Fee' . chr(10) .
				'^' . chr(10);
	}
}

# Write final .qif file to disk.
$qif_file_path = mktime() . '.qif';
$qif_file = fopen($qif_file_path, 'w') or die ('Can\'t open file.');
fwrite($qif_file, $qif);
fclose($qif_file);

# Show download link
echo '<a href="' . $qif_file_path . '">Download QIF</a>';
?>
]]>
0
angelleye http://www.angelleye.com <![CDATA[PHP Class for the PayPal Payments Pro NVP API]]> http://www.angelleye.com/blog/?p=46 2009-05-27T19:49:35Z 2009-05-26T07:43:23Z I wrote this PHP class to handle making calls against PayPal’s NVP API. It allows you to simply create a nested array set of all the data and pass that into the class. The result is an array with all of the PayPal fields returned as well as extra array sets for things like errors, order items, fraud filters, etc.

I’ve been using it awhile already and it’s saved me quite a bit of time. Hopefully it’ll do the same for you!

Complete PHP Class for PayPal Payments Pro NVP API

———————————-
DoDirectPayment Usage Sample
———————————-

<?php
# Add PayPal class
require_once('../PayPalApps/paypal.nvp.class.php');

# Setup the PayPal object
$ppConfig = array('Sandbox' => true);
$pp = new PayPal($ppConfig);

# Populate data arrays for API call.
$DPFields = array(
					'paymentaction' => 'Sale',
					'ipaddress' => '192.168.1.34',
					'returnfmfdetails' => '1'
				);

$CCDetails = array(
					'creditcardtype' => 'Visa',
					'acct' => '4635800000835916',
					'expdate' => '052012',
					'cvv2' => '123',
					'startdate' => ''
				);

$PayerInfo = array(
					'email' => 'tester@testerson.com',
					'business' => 'Testers, LLC'
				);

$PayerName = array(
					'salutation' => 'Mr.',
					'firstname' => 'Tester',
					'middlename' => 'T.',
					'lastname' => 'Testerson',
					'suffix' => 'Jr.'
				);

$BillingAddress = array(
						'street' => '123 Test Ave.',
						'street2' => 'Apt. 3',
						'city' => 'Testersville',
						'state' => 'MO',
						'countrycode' => 'US',
						'zip' => '64030',
						'phonenum' => '555-555-5555'
					);

$ShippingAddress = array(
						'shiptoname' => 'Mr. Tester Testerson Jr.',
						'shiptostreet' => '123 Test Ave',
						'shiptostreet2' => 'Apt. 3',
						'shiptocity' => 'Testersville',
						'shiptostate' => 'MO',
						'shiptozip' => '64030',
						'shiptocountrycode' => 'US',
						'shiptophonenum' => '555-555-5555'
						);

$PaymentDetails = array(
						'amt' => '25.00',
						'currencycode' => 'USD',
						'itemamt' => '15.00',
						'shippingamt' => '10.00',
						'handlingamt' => '',
						'taxamt' => '',
						'desc' => 'This is a test order.',
						'custom' => '',
						'invnum' => '1234-ABC',
						'buttonsource' => '',
						'notifyurl' => ''
					);

# Now combine your data arrays into a single nested array to pass into the class.
$DPData = array(
				'DPFields' => $DPFields,
				'CCDetails' => $CCDetails,
				'PayerInfo' => $PayerInfo,
				'PayerName' => $PayerName,
				'BillingAddress' => $BillingAddress,
				'ShippingAddress' => $ShippingAddress,
				'PaymentDetails' => $PaymentDetails);

# Now we pass the nested array of all our data into the class.
$DPResult = $pp -> DoDirectPayment($DPData);

# Now lets study the result array
echo '<pre />';
print_r($DPResult);
exit();
?>

———————————-
SetExpressCheckout Usage Sample
———————————-

<?php
# Add PayPal class
require_once('../PayPalApps/paypal.nvp.class.php');

# Setup the PayPal object
$ppConfig = array('Sandbox' => true);
$pp = new PayPal($ppConfig);

# Populate data arrays for API call.
$SECFields = array(
					'returnurl' => 'http://www.domain.com/return.php',
					'cancelurl' => 'http://www.domain.com/cancel.php',
					'paymentaction' => 'Sale'
					);

$PaymentDetails = array(
						'amt' => '18.00',
						'currencycode' => 'USD',
						'itemamt' => '10.00',
						'shippingamt' => '5.00',
						'handlingamt' => '2.00',
						'taxamt' => '1.00',
						'desc' => 'This is a test order.',
						'custom' => '',
						'invnum' => '1234-ABC'
						);

# Now combine your data arrays into a single nested array to pass into the class.
$SECData = array('SECFields' => $SECFields, 'PaymentDetails' => $PaymentDetails);

# Now we pass the nested array of all our data into the class.
$SECResult = $pp -> SetExpressCheckout($SECData);

# Now lets study the result array
echo '<pre />';
print_r($SECResult);
exit();

# Now we can just use the returned REDIRECTURL field to redirect the user to PayPal based on our input.
header('Location: ' . $SECResult['REDIRECTURL']);
?>
]]>
1
angelleye http://www.angelleye.com <![CDATA[Angell EYE Custom Web Development]]> http://www.angelleye.com/blog/?p=16 2009-05-20T04:10:43Z 2009-05-20T03:44:08Z Welcome to Angell EYE Custom Development. We’ve switched to a blog format so we can easily and quickly provide our customers with the latest updates and information from Angell EYE. Whether it’s a new solution or press release you’ll be able to quickly see what’s happening!

]]>
0