PayPal API with Zend Framework - php

Hi I want to integrate Paypal API in my Zend FW 1 application.
my code is
$this->setHeaders(
array(
'Authorization' => '<REMOVED>',
'content-type' => 'application/json',
)
);
$this->setMethod('POST');
$this->setParameterGet('payer_id', $company_id);
$this->setParameterGet('number', $cc_number);
$this->setParameterGet('type', $type);
$this->setParameterGet('exp_month', $exp_month);
$this->setParameterGet('exp_year', $exp_year);
$this->setParameterGet('payer_id', $company_id);
$this->setParameterGet('first_name', $first_name);
$this->setParameterGet('last_name', $last_name);
return $this->request();
Debug show this
string(364) "POST /v1/vault/credit-card?number=4417119669820331&type=visa&exp_month=05&exp_year=2019&first_name=john&last_name=travolta HTTP/1.1
Host: api.sandbox.paypal.com
Connection: close
Accept-encoding: gzip, deflate
User-Agent: Zend_Http_Client
Authorization: Bearer <REMOVED>
content-type: application/json
Content-Length: 0
But when I run i get this error from PayPal
"Method Not Allowed"
Where is problem? I do POST and he said that is not allowed? Allowed method are POST, GET, HEAD, OPTIONS. Where i making mistakes?
I want to store credit card

Paypal API requires strict usage of correct requests.
This includes a valid Accept: application/json header and valid
json content being send. You can not set content-type without sending any content
In this case Zend_HTTP_Client's rawData() should be used.

Related

Docusign PHP SDK resending envelope with Demo Account updates the envelope but no email is sent

I am trying to resend an existing envelope that a user may have mislaid or otherwise not received. The API is updating the envelope with the request, but is not resending the email. I am receiving a 200 OK response from the api. This is my call;
$envelopeApi->update($account_id, $env_id, json_encode([resend_envelope => true]));
The logs show the call is successful;
PUT https://demo.docusign.net:7801/restapi/v2/accounts/eb84945a-xxxx-xxxx-xxxx-125dae50be01/envelopes/1e748673-xxxx-xxxx-xxxx-d932f6bdb90e
Content-Type: application/json
Content-Length: 24
Transfer-Encoding: chunked
Accept: application/json
Authorization: Bearer [omitted]
Host: demo.docusign.net
User-Agent: Swagger-Codegen/2.0.1/php
X-DocuSign-SDK: PHP
X-SecurityProtocol-Version: TLSv1.2
X-SecurityProtocol-CipherSuite: ECDHE-RSA-AES256-GCM-SHA384
x-forwarded-for:
{"resend_envelope":true}
200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 60
X-DocuSign-TraceToken: 3f4d4386-xxxx-xxxx-xxxx-ede4199f7f35
{
"envelopeId": "1e748673-xxxx-xxxx-xxxx-d932f6bdb90e"
}
I have read all the threads I can find on SO and none seem to cover my experience. Your help would be appreciated.
For anyone stumbling across this post, this is how to resend an envelope using v2 of the PHP SDK, as provided by dev support. Its a shame the SDK isn't better documented.
$options = new DocuSign\eSign\Api\EnvelopesApi\UpdateOptions();
$options ->setResendEnvelope("True");
$results = $envelopeApi->update(self::$accountID, $envelopeid, "{}", $options);
Thanks to Edwin#DS

PayPal sandbox IPN validation always return INVALID

I googled this question and tried all suggestions but nothing works.
I tried this code: https://developer.paypal.com/docs/classic/ipn/ht_ipn/ but it don't work. Just copy-pasted it and deleted old magick_quotes routunes.
I tried this code: http://samples.geekality.net/view-source.php?file=ipn/ipn_handler.class.php and it also do not work.
In all cases I tried to do following:
$req = 'cmd=_notify-validate&' . file_get_contents('php://input');
To ensure I sent to IPN exactly what it sent to me. In addition I used the debug proxy (Fiddler) and saved what IPN sent to me and what I sent to IPN. The requests bodies are byte-to-byte identical except my request is prefixed by the cmd=_notify-validate& string.
Yes, I checked I use proper sandbox URL. Here are entire requests bodies:
What IPN sent to me: (I just replaced personal data to XXX)
POST http://localhost.loc/en/payment/success/1 HTTP/1.1
Host: localhost.loc
Connection: keep-alive
Content-Length: 921
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Origin: null
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4
mc_gross=1.00&protection_eligibility=Ineligible&payer_id=5XNKM66NSDKC4&tax=0.00&payment_date=05%3A34%3A11+Jun+01%2C+2015+PDT&payment_status=Completed&charset=utf-8&first_name=XXX&mc_fee=0.33&notify_version=3.8&custom=topup%3A262262%3A1%3A1433162020&payer_status=verified&business=XXX&quantity=1&payer_email=XXX&verify_sign=AG58dBsn5g2z8O8NEjotbuJGP14PAIpZ4k26VL8IyhaDPkcDRj002Keq&memo=hmgvjgjhgfjhfggjhfjtfgjh&txn_id=4CN141026K278934Y&payment_type=instant&last_name=XXX&receiver_email=XXX&payment_fee=0.33&receiver_id=DCMXPXGX4QX6J&txn_type=web_accept&item_name=Account+top+up&mc_currency=USD&item_number=Account+262262+top+up&residence_country=US&test_ipn=1&handling_amount=0.00&transaction_subject=topup%3A262262%3A1%3A1433162020&payment_gross=1.00&shipping=0.00&auth=ANSTBwT3znll-gJQZO2cLoV5QJFW9v8W.FqyWxffdtI0L-9mfsoe2xRL44M86Sn2XtYGtcqG4Fjjel1kdYZyxpQ
What I sent to IPN:
POST https://www.sandbox.paypal.com/cgi-bin/webscr HTTP/1.1
Host: www.sandbox.paypal.com
Accept: */*
Content-Length: 942
Content-Type: application/x-www-form-urlencoded
cmd=_notify-validate&mc_gross=1.00&protection_eligibility=Ineligible&payer_id=5XNKM66NSDKC4&tax=0.00&payment_date=05%3A34%3A11+Jun+01%2C+2015+PDT&payment_status=Completed&charset=utf-8&first_name=XXX&mc_fee=0.33&notify_version=3.8&custom=topup%3A262262%3A1%3A1433162020&payer_status=verified&business=XXX&quantity=1&payer_email=XXX&verify_sign=AG58dBsn5g2z8O8NEjotbuJGP14PAIpZ4k26VL8IyhaDPkcDRj002Keq&memo=hmgvjgjhgfjhfggjhfjtfgjh&txn_id=4CN141026K278934Y&payment_type=instant&last_name=XXX&receiver_email=XXX&payment_fee=0.33&receiver_id=DCMXPXGX4QX6J&txn_type=web_accept&item_name=Account+top+up&mc_currency=USD&item_number=Account+262262+top+up&residence_country=US&test_ipn=1&handling_amount=0.00&transaction_subject=topup%3A262262%3A1%3A1433162020&payment_gross=1.00&shipping=0.00&auth=ANSTBwT3znll-gJQZO2cLoV5QJFW9v8W.FqyWxffdtI0L-9mfsoe2xRL44M86Sn2XtYGtcqG4Fjjel1kdYZyxpQ
Can anyone help me what I do wrong?
Thanks.
AARRRRGH!!!!!!!! I have only dirty words to PayPal!!!!!!! The problem was in... (drumroll... tadam!) in the charset field! No, its value must be the same as IPN sent it to you, but... in UPPERCASE! IPN sends it in lowercase! So you MUST modify IPN data to verify it successfully regardless manual tells us to return data back "as-is". PayPal bug?
So my final working code is: (using HTTP_Request2)
protected function verifyPostData() {
$this->request->setBody('cmd=_notify-validate&' . str_replace('=utf-8', '=UTF-8', file_get_contents('php://input')));
$response = $this->request->send();
if ($response->getStatus() != 200) {
throw new \RuntimeException("Transaction data verification request failed with code {$response->getStatus()}");
}
$content = trim($response->getBody());
return ($content == 'VERIFIED');
}
How I did it: I sent the PDT request for this transaction and obtained transaction data. Then I made field to field comparison of PDT and IPN data. PDT have no some IPN fields such as auth, verify_sign and test_ipn. But all other fields seems must be the same. And the only difference was in the characters case of the charset field. Then I tried to verify modified data and unexpectedly it become successful!
This is a recent PayPal bug, when the customer completes a payment and clicks on "Click here to return.." instead of waiting a few seconds, the parameters passed to the PDT script on your site are sent in lowercase.
This also messes up things like a case-sensitive or encoded cm/custom parameter.
Apparently PayPal are aware of it.

Directly upload a video to youtube by pure PHP and OAuth

I just want to send a POST request to YouTube's server to upload a video directly to YouTube via OAuth.
I have an access token and developer key - how could I send a POST request from PHP to YouTube's gdata server?
The POST request I want to send is found here: Sending an Upload API Request
POST /feeds/api/users/default/uploads HTTP/1.1
Host: uploads.gdata.youtube.com
Authorization: Bearer ACCESS_TOKEN
GData-Version: 2
X-GData-Key: key=DEVELOPER_KEY
Slug: VIDEO_FILENAME
Content-Type: multipart/related; boundary="BOUNDARY_STRING"
Content-Length: CONTENT_LENGTH
Connection: close
--<boundary_string>
Content-Type: application/atom+xml; charset=UTF-8
API_XML_request
--BOUNDARY_STRING
Content-Type: VIDEO_CONTENT_TYPE
Content-Transfer-Encoding: binary
<Binary File Data>
--BOUNDARY_STRING--
I tried the below function, and a lot more like it, but it can't send the XML part of the above mentioned POST request.
if (!function_exists('send_post_request'))
{
function send_post_request($url, $data)
{
$context = stream_context_create(array('http' => array('method' => 'POST',
'content' => http_build_query($data))));
$result = file_get_contents($url, FALSE, $context);
return $result;
}
}
I also tried cURL!

Google OpenSocial API issue about Curl Method

I am trying to build an application using Google Opensocial API.
But when i make a POST request with following CURL headers, i am getting 405 Method not allowed error :
CURLOPT_URL : http://www.orkut.com/social/rpc/
CURLOPT_POSTFIELDS : [{"method":"people.get","id":"self","params":{"userId":["#me"],"groupId":"#self","fields":["displayName","currentLocation","thumbnailUrl","gender","name"]}},{"method":"people.get","id":"friends","params":{"userId":["#me"],"groupId":"#friends","fields":["displayName","currentLocation","thumbnailUrl","gender","name"],"count":300}}]
CURLOPT_CUSTOMREQUEST : POST
CURLOPT_RETURNTRANSFER : true
CURLOPT_USERAGENT : osapi 1.0
CURLOPT_FOLLOWLOCATION : 1
CURLOPT_SSL_VERIFYPEER : false
CURLOPT_HEADER : true
CURLINFO_HEADER_OUT : true
CURLOPT_HTTPHEADER : Array
(
[0] => Authorization: OAuth oauth_body_hash="A3ZOHT4b3YMOzEfg+2j3v+N302E=", oauth_nonce="6ad533sdfsb9261ssdfsdf29af7d", oauth_version="1.0", oauth_timestamp="1318236734", oauth_consumer_key="www.mydomain.com", oauth_token="1%2FKhAasdfsd8YX2bfsdfsdf6MsdfsfsdfsdfJYyULWUog", oauth_signature_method="HMAC-SHA1", oauth_signature="osdf4pShOsdfsdf88nnpwsdfsdf9g%3D"
[1] => Content-Type: application/json
[2] => Content-Length: 0
[3] => User-Agent: osapi 1.0
)
Following is the CURL-POST response I am recieving :
["http_code"] => int(405)
["data"] => string(12614)
"HTTP/1.1 405 Method Not Allowed
Content-Type: text/html; charset=UTF-8
Content-Length: 12462
Date: Tue, 14 Jun 2011 08:07:58 GMT
Server: GFE/2.0
I asked about this issue on Google Codes forum and they told me to remove following line from CURL request as my website is hosted on hostgator.
CURLOPT_CUSTOMREQUEST : POST
I tried above thing but still i am getting 405 Method not allowed error. Kindly assist me further on this issue.
Do i need to modify my PHP-CURL code above to send POST request? If so, then please help me..
The Google Social specification has an example in which people.get is requested with GET, not via POST. Generally keep in mind that GET is for requesting information, while POST is for changing existing information.

Google Buzz API OAuth Problem - Using Zend_OAuth (PHP)

I have successfully gotten an access_token, so it's not a problem with the 3-legged process.
The problem starts when I try to add a new post/activity using the Buzz API...
Here is my request:
POST /buzz/v1/activities/#me/#self?alt=json HTTP/1.1
Host: www.googleapis.com
Connection: close
Accept-encoding: gzip, deflate
User-Agent: Zend_Http_Client
Content-Type: application/json
Authorization: OAuth
realm="",oauth_consumer_key="example.com",oauth_nonce="ce29b04ce6648fbb92efc8f 08c1c0091",oauth_signature_method="HMAC-
SHA1",oauth_timestamp="1277934794",oauth_version="1.0",oauth_token="1%2FcBz o5ckGvCAm3wLWh1SDH3xQNoW--
yek1NVfUa1Qqns",oauth_signature="CUezSiMbvxyN1BTeb3uROlIx8gA%3D"
Content-Length: 86
{"data":{"object":{"type":"note","content":"posting on Buzz"}}}
Here is the response:
{"error":{"errors":[{"message":"Unknown authorization header","locationType":"header","location":"Authorization"}],"code":401,"message":"Unknown authorization header"}}
And here is my base string (the string that the signature gets generated from):
POST&https%3A%2F%2Fwww.googleapis.com%2Fbuzz%2Fv1%2Factivities%2F%40me
%2F%40self&oauth_consumer_key%3Dexample.com%26oauth_nonce
%3D50acc6b7ac48304ae9301134d6988cdb%26oauth_signature_method%3DHMAC-
SHA1%26oauth_timestamp%3D1278065599%26oauth_token
%3D1%252FcBzo5ckGvCAm3wLWh1SDH3xQNoW--yek1NVfUa1Qqns%26oauth_version
%3D1.0
I've even tried this other base string (with the alt=json added in):
POST&https%3A%2F%2Fwww.googleapis.com%2Fbuzz%2Fv1%2Factivities%2F%40me
%2F%40self%3Falt%3Djson&oauth_consumer_key%3Dexample.com%26oauth_nonce
%3Dee8704244623bbcc860bf77bfcadeacc%26oauth_signature_method%3DHMAC-
SHA1%26oauth_timestamp%3D1278069221%26oauth_token
%3D1%252FcBzo5ckGvCAm3wLWh1SDH3xQNoW--yek1NVfUa1Qqns%26oauth_version
%3D1.0
I have tried pretty much everything to get this working - not sure why it always says 'Unknown authorization header'... the header looks fine when compared to other ones that work.
Any ideas?
which endpoint did you use to authorize request token?
developer's guide:
Important: Part of the OAuth process
requires that you direct the user to
the Google Authorization service to
approve access for your application.
Google Buzz requires that you use a
different Authorization service
endpoint, located at
https://www.google.com/buzz/api/auth/OAuthAuthorizeToken.com/buzz/api/auth/OAuthAuthorizeToken.
You should use GET or POST method (depending what request you use). By default Zend uses header-method.
$client->setMethod(Zend_Http_Client::GET);

Categories