Jump to content

help with loop for Paypal DoDirectPayment API integration


APuppyDog

Recommended Posts

hey guys. i am not too familiar with how loop works.. or in my case particularly. Here is the situation.

i am trying to pass multiple transactions in a single click using paypal's doDirectPayment nvp api. The credit card number, name, address will be the same but the "invoice number" and "amount" will be different for each transaction. The way i have it now is that if there are multiple transactions, it processes them as a whole so if there are four $25 transactions, it charges one amount, $100 and provides one transaction id. I'd like to be able to set those transactions in a loop, so each transaction is billed individually and have its own transaction id returned from Paypal.

 

an example would be this:

item_ID-----amount

    1    ----- $25

    2    ----- $25

    3    ----- $25

    4    ----- $25

total    ------ $100

 

the code i have currently is this:

<?php

/** DoDirectPayment NVP example; last modified 08MAY23.
*
*  Process a credit card payment. 
*/

$environment = 'sandbox';	// or 'beta-sandbox' or 'live'

/**
* Send HTTP POST Request
*
* @param	string	The API method name
* @param	string	The POST Message fields in &name=value pair format
* @return	array	Parsed HTTP Response body
*/
//function PPHttpPost($methodName_, $nvpStr_) {}


$userRes=mysql_query("SELECT * FROM user where id='".$_SESSION['SESS_USERID']."'");
$userRow=mysql_fetch_array($userRes);

// Set request-specific fields.
$fullname=explode(" ",$userRow['fullname']);
$paymentType = urlencode('Sale');				// or 'Authorization'
$firstName = urlencode($fullname[0]);
$lastName = urlencode($fullname[1]);
$creditCardType = urlencode($card_type);
$creditCardNumber = urlencode($card_no);
// Month must be padded with leading zero
$padDateMonth = urlencode(str_pad($exp_month, 2, '0', STR_PAD_LEFT));
$expYr="20".substr($exp_year,-2);
$expDateYear = urlencode($expYr);
$cvv2Number = urlencode($cvv2);
$address1 = urlencode($userRow['address1']);
$address2 = urlencode($userRow['address2']);
$city = urlencode($userRow['city']);
$state = urlencode($userRow['state']);
$zip = urlencode($userRow['zip']);
$country = urlencode('US');				// US or other valid country code
$amount = urlencode($totalamt);
$currencyID = urlencode('USD');							// or other currency ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')

// Add request-specific fields to the request string.
$nvpStr =	"&PAYMENTACTION=$paymentType&AMT=$amount&CREDITCARDTYPE=$creditCardType&ACCT=$creditCardNumber".
		"&EXPDATE=$padDateMonth$expDateYear&CVV2=$cvv2Number&FIRSTNAME=$firstName&LASTNAME=$lastName".
		"&STREET=$address1&CITY=$city&STATE=$state&ZIP=$zip&COUNTRYCODE=$country&CURRENCYCODE=$currencyID";

// Execute the API operation; see the PPHttpPost function above.
$httpParsedResponseAr = PPHttpPost('DoDirectPayment', $nvpStr);

if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
if($s_list!="")
{
	$updRes=mysql_query("UPDATE cars set s_fee_paid_status='1',seller_paid_date=now() where id in (".$s_list.")");
}
if($b_list!="")
{
	$updRes=mysql_query("UPDATE cars set b_fee_paid_status='1',buyer_paid_date=now() where id in (".$b_list.")");
}

$exp_date=$exp_month."/".$exp_year;
$updRes=mysql_query("UPDATE user set nameoncard='".$nameoncard."',card_type='".$card_type."',card_no='".$card_no."',cvv2='".$cvv2."',exp_date='".$exp_date."' where id='".$_SESSION['SESS_USERID']."'");
//$msgs=urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]);
echo "<script> window.location='somewebfile.php?msgs=1'; </script>";
exit;
} else  {
$msgs=urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]);
/*echo "<script> window.location='somewebfile.php?msgs=2'; </script>";
exit;*/
}

?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.