Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constantly get Authentication+failed.+API+credentials+are+incorrect

I'm trying to create simple PayPal Pay API operation, when I run this code from console it gave me response, that payment is created.

Now, when I'm tring to run it from my controller it gives me

    Authentication+failed.+API+credentials+are+incorrect.

Here is my controller :

     def pay
require 'httpclient'
require 'xmlsimple'
clnt = HTTPClient.new
credentials = {
    'USER' => 'payer_1342623102_biz_api1.gmail.com',
   'PWD' => '1342623141',
   'SIGNATURE' => 'Ay2zwWYEoiRoHTTVv365EK8U1lNzAESedJw09MPnj0SEIENMKd6jvnKL '
 }

header =  {"X-PAYPAL-SECURITY-USERID" => "payer_1342623102_biz_api1.gmail.com",
               "X-PAYPAL-SECURITY-PASSWORD" => "1342623141",
               "X-PAYPAL-SECURITY-SIGNATURE" => "Ay2zwWYEoiRoHTTVv365EK8U1lNzAESedJw09MPnj0SEIENMKd6jvnKL ",
               "X-PAYPAL-REQUEST-DATA-FORMAT" => "NV",
               "X-PAYPAL-RESPONSE-DATA-FORMAT" => "XML",
               "X-PAYPAL-APPLICATION-ID" =>  "APP-80W284485P519543T"
                }
data = {"actionType" => "PAY",
           "receiverList.receiver(0).email"=> "[email protected]",
           "receiverList.receiver(0).amount" => "10",
           "currencyCode" => "USD",
           "cancelUrl" => "http://127.0.0.1:3000",
           "returnUrl" => "http://127.0.0.1:3000",
           "requestEnvelope.errorLanguage" => "en_US"}
uri = "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay"
res = clnt.post(uri, data, header)
@xml = XmlSimple.xml_in(res.content)
payKey = @xml["payKey"].to_s()
payKey = payKey.tr("[]", "")
payKey = payKey[1..20]
redirect_to "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay?cmd=_ap-payment&paykey=#{payKey}"
end

Is everything ok ? Can anyone suggest reason my request fails ?

like image 513
deny7ko Avatar asked Dec 01 '25 02:12

deny7ko


1 Answers

One good man found my error. I redirect user to the wrong url.

This line:

redirect_to "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay?cmd=_ap-payment&paykey=#{payKey}"

Should be:

redirect_to "https://sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=#{paykey}"
like image 107
deny7ko Avatar answered Dec 03 '25 19:12

deny7ko