PAYPAL RESTful API execute call occasional error - paypal

I have fully integrated my website with paypal using paypal RESTful's API PHP SDK. Now my problem is every once in a while on the payment process, once the user approves the payment and it comes back to my website for execution, the API execution request comes back with the following responses from paypal. The HTTP response code's in these scenarios are 400 and 500. Below I have listed the error name and error message which comes as a part of the JSON response I get form paypal on execute action (https://api.paypal.com/v1/payments/payment/PAY-xxxxxxxxxxxxxxxxxxxxxxxxxx/execute):
400 PAYMENT_NOT_APPROVED_FOR_EXECUTION,Payer has not approved payment
500 INTERNAL_SERVICE_ERROR,An internal service error has occurred
In terms of the code I use to make that call I have added the function which executes the payment. I should add that this is working in 98% of times. Below is the code:
public function getExecute()
{
// Payment is cancelled
if (!(Input::get('success') && Input::get('success') == 'true'))
return $this->runPaymentExitProcess();
// No paymentId
if (!Session::has('paymentId'))
return "No payment id to execute";
$paymentId = Session::get('paymentId');
$this->payment = Payment::get($paymentId, $this->apiContext);
// The payer_id is added to the request query parameters when the user is redirected from paypal back to your site
$this->execution->setPayer_id(Input::get('PayerID'));
$response = $this->payment->execute($this->execution, $this->apiContext);
// Check for paypal errors
if (isset($response->name)) {
// When we have a paypal error
if ($this->hasPaypalError($response)) {
$error = array('name' => $response->name, 'message' => $response->message);
Session::put('error', $error);
return (MODE == 'LIVE') ? Redirect::to('/paypalerror') : Redirect::to('/paypalerror'.MODE_PARAM);
die;
}
}
// Unset session
Session::forget('paymentId');
// execution successful
if ($this->addPaymentIdToUser($paymentId))
return (MODE == 'LIVE') ? Redirect::to('/') : Redirect::to('/'.MODE_PARAM);
}
The code is in laravel. Please note that the $this->apiContext is set in the constructor of the class. Also this is the function is the success url which is set in the API under redirect_urls.
Can someone please help me figure out if this issue is coming from my side or Paypal's side?

For the 400 error, this would occur if the user decided not to approve the payment. If you think the payment was actually approved in the web flow then that would be an issue to look into further.
Can you provide the debugId and approximate time (with timezone, or GMT) of a 500 internal server error response, and a 400 if you believe the payment was actually approved by user.

Related

not getting Bitpay notification url at the time of invoice create .. see below code

$invoice->setRedirectURL('https://test/testett/');
// Set URL that Buyer will be redirected to after completing the payment, via GET Request
// Set URL that Buyer will be redirected to after closing the invoice or after the invoice expires, via GET Request
$invoice->setAutoRedirect(true);
// Optional. Learn more at: https://github.com/vrajroham/laravel-bitpay#1-setup-your-webhook-route
$invoice->setNotificationUrl('https://1ba5-45-112-243-81.ngrok.io/laravel-bitpay/webhook');
// This is the recommended IPN format that BitPay advises for all new implementations
$invoice->setExtendedNotifications(true);

MS Bot Framework Response to Facebook Payment Buy Request

When you show a buy button on Facebook the callback to your bot is an "invoke". Details here [Show the buy button and process the payment on facebook messenger with Bot Framework
It is up to the bot to respond to FB with a 200 for success or something else for a failure. No matter what response I've sent Facebook processes the request as if it were successful.
v3.0 of the bot framework with the C# Connector SDK
I've attempted:
Standard reply:
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
Activity replyToConversation = activity.CreateReply();
replyToConversation.Recipient = activity.From;
replyToConversation.Type = "invoke";
connector.Conversations.ReplyToActivity(replyToConversation);
or
return Request.CreateResponse(HttpStatusCode.InternalServerError);
or
return Request.CreateErrorResponse(...);
or
return null;
I've also forced the Controller to respond with an error by throwing a new exception.
There was a suggestion to rely using channelData however channelData seems to only support attachment type replies and what is needed here is a direct reply to the Payment request.
How do I correctly respond to FB to indicate the payment was NOT successful?

How to access response from Paypal Express Checkout?

I am integrating PayPal Express Checkout as shown here.
https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/basic-integration/
I am processing the payment successfully, when the transaction has been authorized I am using actions.payment.get(); to get the information about the transaction.
This returns an object called SyncPromise with all the data I want to use.
console screenshot here
I have tried:
var response = actions.payment.get();
response.value
But I get undefined.
Does anyone how can I access the object element?
You need to call like so:
actions.payment.get().then(function(data) {
console.log(data);
});

PayPal Sandbox suddenly outputting proxy error for adaptive payments

Edit: For some reason it's working again. I did not need to log in to developer.paypal.com either. If anyone knows why, that would be useful. Thanks!
For the past few months I have been developing a site using PayPal's adaptive payments, specifically the chained payments method. I am using the embedded payment method from a site that uses SSL. The integration had been working perfectly for months until a day or two ago. It was even still working right after I imported my old sandbox accounts to the new developer.paypal.com sandbox.
After submitting the payment from the site's form, the browser spins for a minute or two. The error generated after a few minutes is the following:
The proxy server could not handle the request GET
/webapps/adaptivepayment/flow/corepay Reason: Error during SSL
Handshake with remote server
$API_UserName = "us business account from developer.paypal.com sandbox";
$API_Password = "password from developer.paypal.com sandbox";
$API_Signature = "singature from developer.paypal.com sandbox";
// AppID is preset for sandbox use
// If your application goes live, you will be assigned a value for the live environment by PayPal as part of the live onboarding process
$API_AppID = "APP-80W284485P519543T";
$API_Endpoint = "";
if ($Env == "sandbox")
{
$API_Endpoint = "https://svcs.sandbox.paypal.com/AdaptivePayments";
}
else
{
$API_Endpoint = "https://svcs.paypal.com/AdaptivePayments";
}
If I am not mistaken, I believe the error is being generated when the redirect happens from this function here:
function RedirectToPayPal ( $cmd )
{
// Redirect to paypal.com here
global $Env;
$payPalURL = "";
if ($Env == "sandbox")
{
$payPalURL = 'https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay?expType='.$_POST['expType'].$cmd;
}
else
{
$payPalURL = "https://www.paypal.com/webscr?" . $cmd;
}
header("Location: ".$payPalURL);
exit;
}
Edit: I changed the $payPalURL to "https://developer.paypal.com..." as suggested and got the following:
Service Temporarily Unavailable
The server is temporarily unable to service your request due to
maintenance downtime or capacity problems. Please try again later.
After the recent code change this flow now requires you to log in to https://developer.paypal.com first. I am checking to see if this was intentional or is a code bug.
There appears to have been an issue with the sandbox.paypal.com server that disabled adaptive payments for a couple days. Everything seems to be functioning as it had been previously. Thank you to Dennis for his input.
Edit:
This appears to be ongoing and intermittent

Paypal IPN listener issue

I currently have a problem with my Paypal IPN listener and have been receiving the following email from paypal each day:
"Please check your server that handles PayPal Instant Payment Notifications (IPN). IPNs sent to the following URL(s) are failing:
http://www.mysales.ie/create_promo_listener.php"
I have a demo site which enables users to create ads and works perfectly (no problems with IPN), however the proper site that I am developing has this issue (It is on a different host).
I have contacted the host provider and they have said it is not an issue on their side. I have tried php error logs but cant find any issues. I have the exact same code on both sites so I cant understand what the problem is.
<?php include 'ipn_handler.class.php';
/**
* Logs IPN messages to a file.
*/
class Logging_Ipn_Handler extends IPN_Handler
{
public function process(array $post_data)
{
$data = parent::process($post_data);
if($data === FALSE)
{
header('HTTP/1.0 400 Bad Request', true, 400);
exit;
}
$random_number = $_POST['custom'];
file_put_contents( 'logs/listenerTest.txt', "listener = " . $random_number, FILE_APPEND);
header("location:create_promo_creator.php?random_number=" . $random_number);
}
}
date_default_timezone_set('Europe/Oslo');
$handler = new Logging_Ipn_Handler();
$handler->process($_POST);
I have been trying to find the root of the problem for a long time but cant figure it out.
Seems that your $data = parent::process($post_data);
method is returning FALSE.
Do you have any logging instrumentation in your code to verify this?
The easy workaround is to return a 200 response to keep PayPal's IPN system happy, and to log the error for further review.