how to handle paypal notify url in our site? - php

I have paypal form which will have ipn notify url. i have setup notify url in my paypal ipn settings. but it doesn't return to my site. after analyzed for more than 2 days. i found that my controller construct itself i check for current user session exist or not? should i remove the session check in construct not to check for session. Please advise on this.
this is my code. i am using codeigniter application.
function __construct() {
parent::__construct();
$this->load->model('user_model');
// if (!isEmployee()) {
// redirect('information');
//
// }
}
function paypal_ipn(){
$txn_id = $_POST['txn_id'];
$data = array("paypal_transaction_id"=>$txn_id);
$this->db->insert("payments",$data);
}
I have commented out now

Notify url is part of the Instant Payment Notification (IPN) mechanism of PayPal. This URL is called by PayPal to notify about a payment. It is not part of the user session at all so do not check for it.
I recommend you to read the documentation and get the example from here:
documentation IPN

Related

Contact Form 7 and PayPal IPN integration

I need add PayPal IPN on my site in a specific contact form.
I have integrate the funcions for IPN (listener and other) but I don't known how to invoke the Paypal from the CF7" and send the email only AFTER the payment confirm.
I think I have to use the wpcf7_before_send_mail function, but I don't know how.
I add this simple wpcf7_before_send_mail function in my functions.php
add_action("wpcf7_before_send_mail", "wpcf7_do_something_else");
function wpcf7_do_something_else($cf7) {
// get the contact form object
$wpcf = WPCF7_ContactForm::get_current();
$form_id = $contact_form->posted_data['_wpcf7'];
if ($form_id == 2969) {
if (/*Check if payment in the PayPal it's ok */) {
//Send mail and thank you page
} else {
$wpcf->skip_mail = true;
}
}
return $wpcf;
}
But I don't known to check the IPN (i think first I have redirect to paypal url and after i need listen the paypal response).
Also, i have insert in fuction only the $wpcf->skip_mail = true; but the mail but the email is sent however.
Can you help me?
Regards,
Marco
If this is a form post that then redirects the user to a PayPal Payments Standard checkout, there will be no completed payment until later (and some portion of payments will go unpaid), so you will not be able to check for payment at the time the form is posted. That comes later.
The variable notify_url to be specified for IPN is documented here.

Paypal Refund/Cancel Order auto refund

I've been searching about this and everyone seems to say that to refund, you must go to paypal website, etc. then the customer will issue a refund there.
What I need is this:
When the customer wants to refund, an approval will be sent to admin in my website, then when the admin approves, the admin will, inside the website, select the amount of money to payback the customer. (Then I guess, it will direct to paypal and type the email and password?)
Is this possible? That every process is in my website except for the paying? I didn't seem to find solutions, I don't have any lead also. Thanks.
Absolutely Possible,
First of all do make a refund request you must store Paypal's Transaction ID
Once Your admin clicks refund approval button
var refundTransactionRequestType = new RefundTransactionRequestType
{
Version = RefundTransactionRequestVersion, //it must be same version with Express Checkout Request Version
RefundTypeSpecified = true,
TransactionID = transactionId //HERE You need to set Paypal's TransactionID
};
var refundTransactionRequest = new RefundTransactionRequest(
_customSecurityHeaderType, //CustomSecurityHeaderType will have your paypal merchant credentials
new RefundTransactionReq //Your RefundTransactionRequestType
{
RefundTransactionRequest = refundTransactionRequestType
});
RefundTransactionResponse refundTransactionResponse;
try
{
PayPalAPIInterface apiInterface = new PayPalAPIInterfaceClient();
refundTransactionResponse = apiInterface.RefundTransaction(refundTransactionRequest);
}
catch (FaultException err)
{
return 123123;//Error CODE
}
The Code is for C# but it will have the same logic
Here is reference for RefundTransaction SOAP
Here is reference for RefundTransaction NVP

Using PayPal Integration Wizard: Problems with empty variables

What I have to do:
Client defines a quite tricky product.
Price is calculated according to different Parameters via javascript.
Client states, that he wants to pay with PayPal and sends form.
When checking the content of the form, I want to react on his wish to pay via PayPal.
I used the integration wizard. I implemented paypals expresscheckout.php and paypalfunctions.php.
I set the variables at the start of paypalfunctions.php (sandbox). Made the rest of the code as given and tracked it until the paypal-call.
There is a call to PayPal in their own function "hash_call", where they use these variables.
But they are empty.
code in paypalfunctions.php
Defines all the global variables and the wrapper functions
********************************************/
$PROXY_HOST = '127.0.0.1';
$PROXY_PORT = '808';
$SandboxFlag = true;
//'------------------------------------
//' PayPal API Credentials
//' Replace <API_USERNAME> with your API Username
//' Replace <API_PASSWORD> with your API Password
//' Replace <API_SIGNATURE> with your Signature
//'------------------------------------
$API_UserName="myemail";
$API_Password="mypw";
$API_Signature="mysignature";
...
code in hash_call: The function hash_call ist part of paypalfunctions.php
function hash_call($methodName,$nvpStr)
{
...
//declaring of global variables
global $API_Endpoint, $version, $API_UserName, $API_Password, $API_Signature;
...
Whats going wrong?
There is a link zu the wizard: https://devtools-paypal.com/integrationwizard/ecpaypal/code.php
Piet
It is possible that you are using the wrong API Credentials.
I noticed in your example you put the following:
$API_UserName="myemail";
$API_Password="mypw";
$API_Signature="mysignature";
Just to be clear your API User name is not your Email address. Your API Password is not your PayPal Password.
Just in case you need it, here is an example of what API credentials look like and how to request them from your PayPal Account. You can use these same instructions on your Sandbox account as well:
API Credential Information
Also make certain of your endpoint. The endpoint is where you are pointing your customers. Are you pointing them at the live site or the sandbox site?
Just in case you need them, here is the API endpoint information:
PayPal API Endpoint Information
Make certain that if you are using Sandbox Credentials you are using Sandbox endpoints, and if you are using live credentials, make certain to use the live endpoint.

Paypal Sandbox IPN "Email does not match seller"

I am trying to create a paypal subscription button with paypal sandbox. I have created the dev account, created sandbox business and test accounts. Logged into my business test account, went to merchant services -> my saved buttons.
Found the subscription button and copied the code.
I have uploaded the form to my codeigniter controller at: http://422clients.com/ftg/paypal/test
I am using this paypal IPN library for codeigniter: https://github.com/orderly/codeigniter-paypal-ipn
I am using unmodified controller code for now to handle the IPN response because it writes it to the database just fine for testing:
function ipn()
{
$this->load->library('PayPal_IPN'); // Load the library
// Try to get the IPN data.
if ($this->paypal_ipn->validateIPN())
{
// Succeeded, now let's extract the order
$this->paypal_ipn->extractOrder();
// And we save the order now (persist and extract are separate because you might only want to persist the order in certain circumstances).
$this->paypal_ipn->saveOrder();
// Now let's check what the payment status is and act accordingly
if ($this->paypal_ipn->orderStatus == PayPal_IPN::PAID)
{
//Enable database subscription...
}
}
else // Just redirect to the root URL
{
$this->load->helper('url');
redirect('/', 'refresh');
}
}
My problem is that when i click the button on the site and pay with my sandbox test account everything looks totally fine and the payment goes through, but when I look in my database it says: Status: ERROR.
Reason Field says: email business_test#422studios.com does not match seller
business_test#422studios.com is the sandbox account that i generated the button from.
I'm totally lost here. Any help is appreciated.
In your config file, make sure you have this:
$config['paypal_ipn_sandbox_settings'] = array(
'email' => 'business_test#422studios.com',
'url' => 'https://www.sandbox.paypal.com/cgi-bin/webscr',
'debug' => TRUE
);
And that you pass this value in your form:
<input type="hidden" name="business" value="business_test#422studios.com">

pay pal returnurl to return users pay pal account email address

I'm using PHP.
Is it possible when paypal returns to my site after taken the payment that it could also pass me the email address (paypal username) so that I may use this to send them an email?
I'm trying to keep my site as simple as possible and I don't want to ask the customer for a load of information up front.
My ideal flow would be:
Take Payment > Add record to database > email customer with username and password
The customer can then log in and fill the rest in at their own leisure.
Is it possible to get this variable?
Thanks in advance.
Yes...see the receiver_email variable that was passed back.
Guide here: https://cms.paypal.com/cms_content/GB/en_GB/files/developer/IPNGuide.pdf
See Pages 42-43
This page shows the things you can get back from PayPal after they process a payment.
IPN and PDT Variables
Here is on example I made in Codeigniter.
/* Receives a form data from paypal that is processed after payment goes through.
* It will update the database entry with a transaction id.
*/
function epayment_notify(){
$this->load->model('pament_notice_model');
echo "Hi<br>";
$postvars = isset($_POST)? $_POST : array("no post");
/* echo "</pre>Post Vars:<br><pre>";
print_r($postvars);
echo "</pre>Refurl:<br><pre>";
Check for the transaction ID and put it in the pament_notice table if possible.
*/
if (isset($postvars['item_number']) && $postvars['item_number'] > 0 && isset($postvars['txn_id'])){
/* make sure that payment_number is empty on this row. */
log_message('info',"PayPal transaction received.");
if ($this->pament_notice_model->make_sure_payment_number_is_empty($postvars['item_number'])){
//writes the message to the local log file in CI
log_message('debug',"PayPal payment number is empty.");
/* set the txn_id in the slot */
$data = array('payment_number' => $postvars['txn_id']);
$this->db->where('entry_id',$postvars['item_number']);
$this->db->update('pament_notice',$data);
log_message('debug',"payment number updated. item:".$postvars['item_number']);
log_message('debug',"payment actual cost. payment_gross:".$postvars['payment_gross']);
} else {
log_message('error',"PayPal transaction attempted on non-empty payment number.");
if (isset($postvars['item_number']))
log_message('error',"failed request item_number :".$postvars['item_number']);
if (isset($postvars['txn_id']))
log_message('error',"failed request txn_id:". $postvars['txn_id']);
}
} else {
log_message('info',"PayPal payment transaction sent with invalid data.");
if (!isset($postvars['item_number']))
log_message('error',"item_number is not set");
if (isset($postvars['item_number']))
log_message('error',"failed request item_number :".$postvars['item_number']);
if (!isset($postvars['txn_id']))
log_message('error',"txn_id is not set\n");
if (isset($postvars['txn_id']))
log_message('error',"failed request txn_id:". $postvars['txn_id']);
}
}
There are a couple of way of handling this.
The easiest method is to collect that data prior to sending the user to paypal.
Store it in the users current session, and have paypal redirect the user back to your page automatically.
The second is to set up the Payment Data Transfer option. I haven't fully implemented this but there is Documentation on paypal's developer site. It basically sends a token back to your site when the user makes payment and you have to perform another HTTP post to retrieve the user data.

Categories