cnaize
cnaize

Reputation: 3149

Paypal API: NOT json response



I'm trying to execute example from here: https://developer.paypal.com/docs/classic/paypal-payments-pro/gs_PayPalPaymentsPro/

curl -s --insecure https://api-3t.sandbox.paypal.com/nvp -d "USER=platfo_1255077030_biz_api1.gmail.com&PWD=1255077037&SIGNATURE=Abg0gYcQyxQvnf2HDJkKtA-p6pqhA1k-KTYE0Gcy1diujFio4io5Vqjf&METHOD=DoDirectPayment&VERSION=78&PAYMENTACTION=SALE&AMT=5&ACCT=4660997962602322&CREDITCARDTYPE=VISA&CVV2=176&FIRSTNAME=James&LASTNAME=Smith&STREET=FirstStreet&CITY=SanJose&STATE=CA&ZIP=95131&COUNTRYCODE=US&EXPDATE=092015"

Documentation says:

Request method,       format      Response format
 HTTP    GET     Name/value pairs       JSON

But I receives:

TIMESTAMP=2015%2d01%2d30T12%3a14%3a08Z&CORRELATIONID=474de7dae8e82&ACK=Success&VERSION=78&BUILD=15009693&AMT=5%2e00&CURRENCYCODE=USD&AVSCODE=X&CVV2MATCH=M&TRANSACTIONID=93V64243P1844913T

Why? How to get json response?

I tried to set:

VERSION=95

but didn't help.

Upvotes: 0

Views: 900

Answers (2)

Naresh Kumar
Naresh Kumar

Reputation: 1736

As document states the paypal NVP api doesn't straight away provide json response.

The way attained to process the response goes like below, In PHP

parse_str($response,$responseArray);

$jsonResponse = json_encode($responseArray);

helped me to get the array from the response string and in turn converted to json.

Edit : you first need to decode the urlencoded string.

For that

$response = urldecode($response);

Before parsing the response to array.

Upvotes: 1

geewiz
geewiz

Reputation: 2206

While I do see the documentation you quoted (from https://developer.paypal.com/docs/classic/paypal-payments-pro/gs_PayPalPaymentsPro/), I think it's flat-out wrong.

I don't believe the classic PayPal APIs support JSON (except Adaptive Payments, which was written later @ PayPal & is thus a bit more modern in some ways, including the JSON support).

See https://developer.paypal.com/docs/classic/api/gs_PayPalAPIs/, which describes the headers taht you can use to request JSON from the Adaptive APIs but clarifies that the other classic APIs don't support it.

Upvotes: 0

Related Questions