• Medieval Tech Guy
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies

I'm attempting to create a php file which serves both as an IPN listner to recieve payment information from paypal, and to perform and upsert() to salesforce with the collected information. I believe that I have the gyst of the IPN listner down, as well as creating the connection to salesforce. However, I am having some trouble setting up the upsert() portion of the code. I have been looking online, and found some tutorials on this, but most of them are unclear, and usually related to databases, rather then updating from a single record (i.e. http://wiki.developerforce.com/page/Salesforce_PHP_Upsert_Tutorial). Below is the code I have come up with so far. Right now I am lost as to how to create an object with the contact's information that salesforce will be able to read using the upsert() command. Will the below code execute correctly to create a new contact in salesforce?

 

<?php
// Revision Notes
// 11/04/11 - changed post back url from https://www.paypal.com/cgi-bin/webscr to https://ipnpb.paypal.com/cgi-bin/webscr
// For more info see below:
// https://www.x.com/content/bulletin-ip-address-expansion-paypal-services
// "ACTION REQUIRED: if you are using IPN (Instant Payment Notification) for Order Management and your IPN listener script is behind a firewall that uses ACL (Access Control List) rules which restrict outbound traffic to a limited number of IP addresses, then you may need to do one of the following:
// To continue posting back to https://www.paypal.com to perform IPN validation you will need to update your firewall ACL to allow outbound access to *any* IP address for the servers that host your IPN script
// OR Alternatively, you will need to modify your IPN script to post back IPNs to the newly created URL https://ipnpb.paypal.com using HTTPS (port 443) and update firewall ACL rules to allow outbound access to the ipnpb.paypal.com IP ranges (see end of message)."


// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// post back to PayPal system to validate

$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";

// If testing on Sandbox use:
// $header .= "Host: www.sandbox.paypal.com:443\r\n";
$header .= "Host: ipnpb.paypal.com:443\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

// If testing on Sandbox use:
//$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
$fp = fsockopen ('ssl://ipnpb.paypal.com', 443, $errno, $errstr, 30);

// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$address_city = $_POST['address_city'];
$address_country = $_POST['address_country'];
$address_state = $_POST['address_state'];
$address_status = $_POST['address_status'];
$address_street = $_POST['address_street'];
$address_zip = $_POST['address_zip'];
$payment_date = $_POST['payment_date'];
$payment_fee = $_POST['payment_fee'];
$payment_gross = $_POST['payment_gross'];
$payment_status = $_POST['payment_status'];


if (!$fp) {
// HTTP ERROR
}
else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
if ($payment_status = "Completed") {
$wsdl = 'enterprise-wsdl.xml';
$user = 'example@epixa.com';
$pass = 'supersecure';
$token = '*****';

$client = new SforceEnterpriseClient();
$client->createConnection($wsdl);
$client->login($user, $pass . $token);

 

$sObject = new sObject();
$sObject->type = 'Contact';
$sObject->Account_Name = $first_name + $last_name;
$sObject->Address_City = $address_city;
$sObject->Address_Country = $address_country;
$sObject->Address_State = $address_state;
$sObject->Address_Street = $address_street;
$sObject->Address_Zip = $address_zip;

client.upsert('Account Name', $sObject);



}
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment

}

}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation

$mail_From = "From: me@mybiz.com";
$mail_To = "*****";
$mail_Subject = "INVALID IPN";
$mail_Body = $req;

foreach ($_POST as $key => $value){
$emailtext .= $key . " = " .$value ."\n\n";
}

mail($mail_To, $mail_Subject, $emailtext . "\n\n" . $mail_Body, $mail_From);

}
}
fclose ($fp);
}
?>

Hello,

 

I am attempting to link my company's salesforce account to the paypall donation process, so that when someone donates to the organization, salesforce creates a new contact (if necessary) and donation to model the paypal transaction. I am gathering that this would best be done using Paypal's SOAP API, sending a page to salesforce and writing an Apex class to interpret it  and execute the account creation. I am not sure how exactly to send the data from paypal to salesforce however, nor am I clear on the details of the coding that would be required on either end to send and recieve the data.

 

I have not developed in Apex before, but I am an IT student who has taken several programming corses, and feel relatively proficient in Java. Any help would be greatly appreciated. 

 

 

Nathan Gedamke

IT Coordinator

Orlando Day Nursery

I'm attempting to create a php file which serves both as an IPN listner to recieve payment information from paypal, and to perform and upsert() to salesforce with the collected information. I believe that I have the gyst of the IPN listner down, as well as creating the connection to salesforce. However, I am having some trouble setting up the upsert() portion of the code. I have been looking online, and found some tutorials on this, but most of them are unclear, and usually related to databases, rather then updating from a single record (i.e. http://wiki.developerforce.com/page/Salesforce_PHP_Upsert_Tutorial). Below is the code I have come up with so far. Right now I am lost as to how to create an object with the contact's information that salesforce will be able to read using the upsert() command. Will the below code execute correctly to create a new contact in salesforce?

 

<?php
// Revision Notes
// 11/04/11 - changed post back url from https://www.paypal.com/cgi-bin/webscr to https://ipnpb.paypal.com/cgi-bin/webscr
// For more info see below:
// https://www.x.com/content/bulletin-ip-address-expansion-paypal-services
// "ACTION REQUIRED: if you are using IPN (Instant Payment Notification) for Order Management and your IPN listener script is behind a firewall that uses ACL (Access Control List) rules which restrict outbound traffic to a limited number of IP addresses, then you may need to do one of the following:
// To continue posting back to https://www.paypal.com to perform IPN validation you will need to update your firewall ACL to allow outbound access to *any* IP address for the servers that host your IPN script
// OR Alternatively, you will need to modify your IPN script to post back IPNs to the newly created URL https://ipnpb.paypal.com using HTTPS (port 443) and update firewall ACL rules to allow outbound access to the ipnpb.paypal.com IP ranges (see end of message)."


// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// post back to PayPal system to validate

$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";

// If testing on Sandbox use:
// $header .= "Host: www.sandbox.paypal.com:443\r\n";
$header .= "Host: ipnpb.paypal.com:443\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

// If testing on Sandbox use:
//$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
$fp = fsockopen ('ssl://ipnpb.paypal.com', 443, $errno, $errstr, 30);

// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$address_city = $_POST['address_city'];
$address_country = $_POST['address_country'];
$address_state = $_POST['address_state'];
$address_status = $_POST['address_status'];
$address_street = $_POST['address_street'];
$address_zip = $_POST['address_zip'];
$payment_date = $_POST['payment_date'];
$payment_fee = $_POST['payment_fee'];
$payment_gross = $_POST['payment_gross'];
$payment_status = $_POST['payment_status'];


if (!$fp) {
// HTTP ERROR
}
else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
if ($payment_status = "Completed") {
$wsdl = 'enterprise-wsdl.xml';
$user = 'example@epixa.com';
$pass = 'supersecure';
$token = '*****';

$client = new SforceEnterpriseClient();
$client->createConnection($wsdl);
$client->login($user, $pass . $token);

 

$sObject = new sObject();
$sObject->type = 'Contact';
$sObject->Account_Name = $first_name + $last_name;
$sObject->Address_City = $address_city;
$sObject->Address_Country = $address_country;
$sObject->Address_State = $address_state;
$sObject->Address_Street = $address_street;
$sObject->Address_Zip = $address_zip;

client.upsert('Account Name', $sObject);



}
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment

}

}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation

$mail_From = "From: me@mybiz.com";
$mail_To = "*****";
$mail_Subject = "INVALID IPN";
$mail_Body = $req;

foreach ($_POST as $key => $value){
$emailtext .= $key . " = " .$value ."\n\n";
}

mail($mail_To, $mail_Subject, $emailtext . "\n\n" . $mail_Body, $mail_From);

}
}
fclose ($fp);
}
?>

Hello,

 

I am attempting to link my company's salesforce account to the paypall donation process, so that when someone donates to the organization, salesforce creates a new contact (if necessary) and donation to model the paypal transaction. I am gathering that this would best be done using Paypal's SOAP API, sending a page to salesforce and writing an Apex class to interpret it  and execute the account creation. I am not sure how exactly to send the data from paypal to salesforce however, nor am I clear on the details of the coding that would be required on either end to send and recieve the data.

 

I have not developed in Apex before, but I am an IT student who has taken several programming corses, and feel relatively proficient in Java. Any help would be greatly appreciated. 

 

 

Nathan Gedamke

IT Coordinator

Orlando Day Nursery