PayPal SDK: No Server Response when Paying with PayPal Account - paypal

I have scoured the docs and this tutorial about 100 times but can't figure out how to go through the payment process using a PayPal account as opposed to a credit card. I have gotten the credit card payment to go through just fine.
In the aforementioned tutorial, it is stated that I am supposed to expect a JSON response from the server after making an OAuth credential:
$sdkConfig = array(
"mode" => "sandbox"
);
$cred = new OAuthTokenCredential("clientID","clientSecret", $sdkConfig);
I get absolutely no server response despite geting a '200 OK' status from the server.
Initially I had my code set up like a bunch of other tutorials:
$apiContext = new ApiContext(
new OAuthTokenCredential(
'clientID', // ClientID
'clientSecret' // ClientSecret
)
);
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item1 = new Item();
$item1->setName("Donation squares.");
$item1->setCurrency('USD');
$item1->setQuantity(1);
$item1->setPrice(1);
$itemList = new ItemList();
$itemList->setItems(array($item1));
$amountDetails = new Details();
$amountDetails->setSubtotal('7.41');
$amountDetails->setTax('0.03');
$amountDetails->setShipping('0.03');
$amount = new Amount();
$amount->setCurrency('USD');
$amount->setTotal('7.47');
$amount->setDetails($amountDetails);
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription('This is the payment transaction description.');
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("https://devtools-paypal.com/guide/pay_paypal/php?success=true");
$redirectUrls->setCancelUrl("https://devtools-paypal.com/guide/pay_paypal/php?cancel=true");
$payment = new Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
$payment->setTransactions(array($transaction));
try{
$payment->create($apiContext);
} catch(Exception $e){
echo $e
exit(1);
}
None of this works either - no response from the server whatsoever.
ANSWER / COMMENT
You're not supposed to be looking for a JSON response after all. If the payment is successfully created, an approval URL should be generated by running
$payment->getApprovalLink();
The user then follows this link to finalize his/her payment.

You might be interested in following a very simple instruction here at PayPal-PHP-SDK, that explains how to make calls using PayPal PHP SDK. I know you have already gone through that, and are looking for how to create a payment using PayPal.
I am not sure you are aware of this, but PayPal-PHP-SDK comes along with a lot of samples, that you could run by just one simple command (if you have PHP 5.4 or higher). One of the first sample have the instructions and code to make PayPal Call.
There are two steps involved in that.
Create a Payment. Receive a approval_url link to be used to ask the user to complete Paypal flow over any browser.
Once the user accepts the payment on paypal website, it will be redirected back to your website, where you execute the payment.
Both the code samples are provided here and here.
Let me know if this helps, and you have any more questions. I would be more than happy to help.

Related

PayPal Smart Payment Buttons integration with server-side REST API

I know there are a few questions regarding PayPal Integration but I'm trying to implement PayPal Express Checkout with Smart Buttons and REST API and no success.
What I want to do is:
Create a Payment Authorization (with payidand orderid)
Send this payid to the client (javascript) to be approved.
Redirect after payment to a confirmation page.
I have already created a Payment Authorization with the code bellow:
<?php
// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader
// Used for composer based installation
require __DIR__ . '/PayPal-PHP-SDK/autoload.php';
// Use below for direct download installation
// require __DIR__ . '/PayPal-PHP-SDK/autoload.php';
// After Step 1
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'client id', // ClientID
'cliente secret' // ClientSecret
)
);
// After Step 2
$payer = new \PayPal\Api\Payer();
$payer->setPaymentMethod('paypal');
$amount = new \PayPal\Api\Amount();
$amount->setTotal('1.00');
$amount->setCurrency('USD');
$transaction = new \PayPal\Api\Transaction();
$transaction->setAmount($amount);
$redirectUrls = new \PayPal\Api\RedirectUrls();
$redirectUrls->setReturnUrl("https://example.com/your_redirect_url.html")
->setCancelUrl("https://example.com/your_cancel_url.html");
$payment = new \PayPal\Api\Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setTransactions(array($transaction))
->setRedirectUrls($redirectUrls);
// After Step 3
try {
$payment->create($apiContext);
echo $payment;
echo "\n\nRedirect user to approval_url: " . $payment->getApprovalLink() . "\n";
echo $data= json_encode($payment->id, JSON_PRETTY_PRINT), "\n";
echo "</br>";echo "</br>";
echo $data= $payment->id;
}
catch (\PayPal\Exception\PayPalConnectionException $ex) {
// This will print the detailed information on the exception.
//REALLY HELPFUL FOR DEBUGGING
echo json_encode($ex->getData()->id, JSON_PRETTY_PRINT), "\n";
echo "</br>";echo "</br>";
echo $ex->getData()->id;
}
?>
My setup is as following (Please, correct if it's wrong):
User chooses the item and submits the form.
User is redirected to a new page with a new form and then fills the form with his name and other personal informations and then submits the form to be saved in the database and generate the Payment Authorization.
User should be redirected to a final page with Smart Buttons to complete the payment.
User should be redirected to a confirmation page, confirming his payment was successfully made.
The problem is that I'm stuck in the step 2 because once I generate the Payment Authorization, I don't know how to pass this id (and other required parameters) to the client, in this new page that is supposed to show the Smart Payment Buttons to complete the transaction.
I'm following along with the tutorial in PayPal documentation but I'm not able to understand.
The JavaScript makes calls to my server to get the payid, it works, but it generates a new payid and a new Payment Order, i want to use the one that was previously created when the user submitted the form and then, somehow, pass it to the final page with the Smart Buttons to complete the transaction and redirect to a confirmation page.
My Javascript:
<script>
paypal.Button.render({
onApprove: function(data) {
return fetch('/my-server/get-paypal-transaction', {
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
orderID: data.orderID
})
}).then(function(res) {
return res.json();
}).then(function(details) {
alert('Transaction approved by ' + details.payer_given_name);
}, '#paypal-button');
</script>
The problem is that it generates a new orderID, a new transaction, and I want to retrieve the transaction that was generated when the user submitted the form in the step 2 but I don't know what I should do.
Ultimately what I need is:
Get the Payment Authorization and pass it to the Client (final page with the buttons)
Redirect the users after payment complete.
You are looking for this front-end: https://developer.paypal.com/demo/checkout/#/pattern/server
For your backend, you should use the latest v2/orders SDK: https://github.com/paypal/Checkout-PHP-SDK
(Your v1/payments backend will work, but that SDK is deprecated and there is no reason to use it for a new integration)

Paypal SDK and IPN callback not working

I'm developing an affiliate script with the Paypal Adaptive Payments SDK. I have the following code:
$payRequest = new PayRequest(new RequestEnvelope("en_US"), 'PAY',$arrPaypal ['paypal_return'] , 'USD', $receiverList, $arrPaypal['paypal_return']);
$payRequest->IpnNotificationUrl = $arrPaypal['paypal_callback'];
$payRequest->memo = 'Payment for ' . $arrUserInfo['plan_title'];
$payRequest->trackingId = $intID;
However it is not firing the callback script. The url is my http:// ipaddress /script.php. If I set it in the paypal sandbox I get a hit but it's not an adaptive payments response as detailed in the sdk. Could someone please explain how to enable it?
You may have gotten the case of the IPN setter wrong. Try ipnNotificationUrl instead of IpnNotificationUrl

How to get secure token when using "Hosted Checkout Pages" and RestApiSDK - ASP.Net

Is it possible to use the RestApiSDK to get a secure token when using "Hosted Checkout Pages"? If so please show example. (C# preferred.)
The secure token I am referring to is described on page 31 here:
https://www.paypalobjects.com/webstatic/en_US/developer/docs/pdf/payflowgateway_guide.pdf
Please realize that I am not using "Express Checkout". (There is a lot of confusion between the old PayPal products and the new products in the PayPal documentation.)
One example I found here on StackOverflow has the following issues:
The links to the SDK and docs are dead.
The DOSecureTokenAuth.cs file does not exist in any SDK or example that I can find.
PayPal's Payflow Gateway SDK Example not working
In this example the author was not able to copy the code from the source files.
http://forums.asp.net/t/1798900.aspx/1
Thank you,
Chuck
https://github.com/paypal/rest-api-sdk-dotnet please look into this
or you can use
payflow_dotnet.dll
Please look into this code of payflow_dotnet.dll
public void CreateAuthorization()
{
// Create the Payflow Connection data object with the required connection details.
// The PAYFLOW_HOST property is defined in the webconfig
PayflowConnectionData Connection = new PayflowConnectionData();
// Create Invoice
Invoice Inv = new Invoice();
// Set Amount
Currency Amt = new Currency(new decimal(premiumAmount), "USD");
//adding the amount to invoice
Inv.Amt = Amt;
//creating a new express check out request
ExpressCheckoutRequest currRequest = new ECSetRequest(WebConfigkeys.ReturnToApplication, WebConfigkeys.ReturnToApplication);
PayPalTender currTender = new PayPalTender(currRequest);
//creating a new transaction
SaleTransaction currTransaction = new SaleTransaction(User, Connection, Inv, currTender, PayflowUtility.RequestId);
//submitting the transaction and accepting the response message
Response Resp = currTransaction.SubmitTransaction();
if (Resp != null)
{
TransactionResponse TrxnResponse = Resp.TransactionResponse;
ExpressCheckoutResponse eResponse = Resp.ExpressCheckoutSetResponse;
if ((TrxnResponse != null) && (eResponse != null))
{
eResponse.Token;//get your token
}
}
}
Add this to Web Config
<add key="PAYFLOW_HOST" value="pilot-payflowpro.paypal.com" />
It is not currentlypossible. The REST API's do not support the Hosted Checkout payment method. The REST process allows for PayPal transactions (very similar to Express Checkout) and credit card payments (where you pass the billing information to PayPal for verification).
The post you mentioned - PayPal's Payflow Gateway SDK Example not working - is for the Payflow SDK and Payflow does not support REST.

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.