Wednesday 15 February 2012

php - PayPal Rest API for Payments returns NULL in the sandbox -


I have a sandbox account with PayPal, I use the curl on PPL to retrieve the token through the API However, the process of a test card only taps. Anyone have any problems with code? Is this a known issue with PayPal sandbox? The snippet clients are given below, however, as mentioned earlier, using my actual credentials, I can successfully call for the token again.

To create a request:

  & lt ;? Php class psPayPal {Private $ Tokens = 'https://api.sandbox.paypal.com/v1/OAuth2/Token'; Private $ payment url = 'https://api.sandbox.paypal.com/v1/payments/payment'; Private $ client = 'dlgzdfkja; Scandfucks djfkjddfjjjjjjfkjkjkdfjfjdjffjjf; J '; Private $ secret = 'klj; Akjdfjeieiadfaldkjfelkajsdfkjaejeiejisadif; Alkdsfj; Kjjie '; Private $ Tokens; Private $ TokensHandle; Private $ PaymentHandle; Public function __ composition () {$ this- & gt; Tokenshadele = curl_init ($ this-> tokenurl); $ This- & gt; BuildTokenRequest (); } Public function buildTokenRequest () {$ header = array ('Accept: Application / Jason', 'Accept-language: en_US'); $ User = $ this- & gt; Client ':' $ This- & gt; secret; $ Data = 'grant_type = client_credentials'; Curl_setopt ($ this-> TokenHandle, CURLOPT_HTTPHEADER, $ header); Curl_setopt ($ this-> TokenHandle, CURLOPT_USERPWD, $ user); Curl_setopt ($ this-> TokenHandle, CURLOPT_POSTFIELDS, $ data); Curl_setopt ($ this-> TokenHandle, CURLOPT_RETURNTRANSFER, true); $ This- & gt; CommitTokenRequest (); } Public function cumTTTM () {$ response = json_decode (curl_exec ($ this-> tokenhandle)); $ This- & gt; Token = $ response- & gt; Access_token; Curl_close ($ this-> tokenHandle); } Public Functions Construction Payment Request ($ cost = '', $ description = '') {$ this- & gt; Payment Handle = curl_init ($ this-> Payment URL); $ Header = array ('Accept: App / Jason', 'Approved-language: en_US', 'Authority: Bearer'. $ This- & gt; Token); $ Data = array ('intent' = & gt; 'sale', 'donor' => array ('payment_maston' = & gt; 'credit card', 'funding_instriggers' =' gt; array (array 'credit_card' = & Gt; array ('number' = & gt; '550000555555', 'type' = & gt; mastercard ',' expired_ur = '>' 2018 ',' cvv2 '=> 111; 'Array' ('first_name' = & gt; 'joe', 'last_name' = & gt; 'shoppers'))), 'transaction' = & gt; array (array ('zodiac' = & gt; array ('total' > '39 .54 ',' currency '=>' US Dollar '),' Description '= & gt;' This is descrription for my hat '))); $ D = json_encode ($ data); Curl_setopt ($ this-> Payment Handle, CURLOPT_HTTPHEADER, $ header); Curl_setopt ($ this-> Payment Handle, CURLOPT_POSTFIELDS, $ d); Curl_setopt ($ this-> Payment Handle, CURLOPT_RETURNTRANSFER, true); $ This- & gt; CommitPaymentRequest (); } Public function commitPaymentRequest () {$ response = json_decode (curl_exec ($ this- & gt; Payment Handle)); Var_dump ($ response); Curl_close ($ this-> PaymentHandle); }}? & Gt;   

I have tried with many options, although I believe the code above is to be completed. I have also certified JSON which I am sending with JSON lint. JSON is as follows: ["{{" intent ":" sale "," donor ": {" payment_method ":" credit_card "," funding_instruments ": [{" credit_card ": {" number ":" "" "" "" "" "" "" "," Type ":" mastercard "," expired_yure ":" 2018 "," cvv2 ":" 111 "," first_name ":" joe "," lastname ":" shopper "}} ] "," Transaction ": [" total ":" 39.54 "," currency ":" USD "}," description ":" this is descrription for my hat "}] < P>}

Any suggestions would be greatly appreciated!

Header, Content Type: Application / Jason H For some reason, PHP had guessed the right material-type in the token request (possibly due to the acceptance header), but when passed, the JSON-array changed the content type to app / XML Now all good!

No comments:

Post a Comment