Export data with PHPexcel but got an error - codeigniter-3

The code where the error occurs:
This is my controller:
require (APPPATH.'libraries/PHPExcel.php');
require (APPPATH.'libraries/PHPExcel/Writer/Excel2007.php');
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
//Nama File
header('Content-Disposition: attachment;filename="report.xlsx"');
//Download
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save("php://output");
}
}
This is my error:
Fatal error: Cannot redeclare class PHPExcel in C:\xampp\htdocs\e-sabusemusim\application\libraries\PHPExcel.php on line 35

Related

PayPal Orders API - cannot specify customer phone number

PayPal rejects my request to create an order (400 bad Request) if I include the customer's phone number.
I am using the V2 Orders API, using C and CURL.
Here is an example of the JSON data I POST to
https://api.sandbox.paypal.com/v2/checkout/orders
{
intent:"CAPTURE",
payer:
{
name:
{
given_name:"BOB",
surname:"SMITH"
},
email_address:"bob#domain.com",
phone:
{
country_code:"011",
national_number:"4162876593"
},
address:
{
address_line_1:"4180 YONGE STREET",
admin_area_2:"TORONTO",
admin_area_1:"ON",
postal_code:"M1S 2A9",
country_code:"CA"
}
},
purchase_units:
[
{
amount:
{
currency_code:"CAD",
value:"90.00"
}
}
],
application_context:
{
brand_name:"Benefit Gala",
landing_page:"LOGIN",
shipping_preference:"NO_SHIPPING",
user_action:"PAY_NOW",
payment_method:
{
payee_preferred:"IMMEDIATE_PAYMENT_REQUIRED"
},
return_url:"https://Gala.domain.com/cgi-bin/paypal?FZ=4&MF=4&K=SMITH&MR=M&PP=Y",
cancel_url:"https://Gala.domain.com/cgi-bin/paypal?FZ=4&MF=4&K=SMITH&MR=M&PP=C"
}
}
I have tried a large variety of ways of specifying the phone number.
phone:{ country_code:"01", national_number:"14162876593" },
phone:{ country_code:"01", phone_number: { national_number:"14162876593" } },
and many others.
If I omit the phone number entirely, my request is accepted and the order is created and it can be subsequently captured.
If I include any variant of a phone number object, I get a 400 Bad Request returned.
Somewhere in the PayPal documentation it mentions that in order for the phone number to "be available" it is necessary to turn on Contact Number Required in the merchant account preferences. I have tried all three choices (On, Off, Optional) without effect.
The PayPal documentation has very few detailed examples and most of what I find with Google is for a language library like Java or PHP, which doesn't help me.
Is anyone passing a payer phone number when creating an order ? A sample of your JSON please !
The payer's definition (from the api doc) states that:
The phone.phone_number supports only national_number
So I don't think it'll accept the the country code.
Also the phone attribute in the payer's definition is of type phone_with_type :
So its content should follow this structure:
{
"phone_type" : "HOME",
"phone_number" : {
"national_number" : "4162876593"
}
}
I'm not familiar with paypal's api, but it seems to me (unless I'm mistaken) that your example doesn't match what's described the api's documentation.
Here is an example from paypal's documentation that I think is similar to what you want to do :
<script>paypal.Buttons({
enableStandardCardFields: true,
createOrder: function(data, actions) {
return actions.order.create({
intent: 'CAPTURE',
payer: {
name: {
given_name: "PayPal",
surname: "Customer"
},
address: {
address_line_1: '123 ABC Street',
address_line_2: 'Apt 2',
admin_area_2: 'San Jose',
admin_area_1: 'CA',
postal_code: '95121',
country_code: 'US'
},
email_address: "customer#domain.com",
phone: {
phone_type: "MOBILE",
phone_number: {
national_number: "14082508100"
}
}
},
purchase_units: [
{
amount: {
value: '15.00',
currency_code: 'USD'
},
shipping: {
address: {
address_line_1: '2211 N First Street',
address_line_2: 'Building 17',
admin_area_2: 'San Jose',
admin_area_1: 'CA',
postal_code: '95131',
country_code: 'US'
}
},
}
]
});
}
}).render("body");
</script>
Update : Test program and results from Paypal's Sandbox
I added a test program at the end of the answer (and its output from my testing).
The program sends 4 requests using 4 json payloads:
the 1st one is the same as the example from the question.
the 2nd one is the same as the 1st without the phone attribute
the 3rd one is the same as the 1st but all the attribute names are quoted
the 4th one is the same as the 3rd one but the phone attribute structure follows the definition from the api doc.
In my testing (in paypal's sandbox), the first 3 jsons result in a response with a 400 Bad Request status code. Only the 4th one works and result in a response with a 201 Created status code.
Test Program
Before using the program the string ACCESS_TOKEN_HERE should be replaced by a valid access token (how to generate it).
To build the program with gcc : gcc -lcurl -o test-paypal test-paypal.c
#include <stdio.h>
#include <curl/curl.h>
void create_order(CURL* curl, char* payload, struct curl_slist *auth_header){
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "https://api-m.sandbox.paypal.com/v2/checkout/orders");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, auth_header);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, payload);
res = curl_easy_perform(curl);
long http_code = 0;
curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code);
if (http_code >= 200 && http_code < 300 && res != CURLE_ABORTED_BY_CALLBACK)
{
printf("\n******************************** SUCCESS *********************************");
printf("\n******************************** SUCCESS *********************************");
printf("\n******************************** SUCCESS *********************************\n");
}
else
{
printf("\n******************************** ERROR *********************************");
printf("\n******************************** ERROR *********************************");
printf("\n******************************** ERROR *********************************\n");
}
}
int main(char** args){
char* request1 = "{\n"
" intent:\"CAPTURE\",\n"
" payer:{\n"
" name:{\n"
" given_name:\"BOB\",\n"
" surname:\"SMITH\"\n"
" },\n"
" email_address:\"bob#domain.com\",\n"
" phone:{\n"
" country_code:\"011\",\n"
" national_number:\"4162876593\"\n"
" },\n"
" address:{\n"
" address_line_1:\"4180 YONGE STREET\",\n"
" admin_area_2:\"TORONTO\",\n"
" admin_area_1:\"ON\",\n"
" postal_code:\"M1S 2A9\",\n"
" country_code:\"CA\"\n"
" }\n"
" },\n"
" purchase_units:[\n"
" {\n"
" amount:{\n"
" currency_code:\"CAD\",\n"
" value:\"90.00\"\n"
" }\n"
" }\n"
" ],\n"
" application_context:{\n"
" brand_name:\"Benefit Gala\",\n"
" landing_page:\"LOGIN\",\n"
" shipping_preference:\"NO_SHIPPING\",\n"
" user_action:\"PAY_NOW\",\n"
" payment_method:{\n"
" payee_preferred:\"IMMEDIATE_PAYMENT_REQUIRED\"\n"
" },\n"
" return_url:\"https://Gala.domain.com/cgi-bin/paypal?FZ=4&MF=4&K=SMITH&MR=M&PP=Y\",\n"
" cancel_url:\"https://Gala.domain.com/cgi-bin/paypal?FZ=4&MF=4&K=SMITH&MR=M&PP=C\"\n"
" }\n"
"}";
char* request2 = "{\n"
" intent:\"CAPTURE\",\n"
" payer:{\n"
" name:{\n"
" given_name:\"BOB\",\n"
" surname:\"SMITH\"\n"
" },\n"
" email_address:\"bob#domain.com\",\n"
" address:{\n"
" address_line_1:\"4180 YONGE STREET\",\n"
" admin_area_2:\"TORONTO\",\n"
" admin_area_1:\"ON\",\n"
" postal_code:\"M1S 2A9\",\n"
" country_code:\"CA\"\n"
" }\n"
" },\n"
" purchase_units:[\n"
" {\n"
" amount:{\n"
" currency_code:\"CAD\",\n"
" value:\"90.00\"\n"
" }\n"
" }\n"
" ],\n"
" application_context:{\n"
" brand_name:\"Benefit Gala\",\n"
" landing_page:\"LOGIN\",\n"
" shipping_preference:\"NO_SHIPPING\",\n"
" user_action:\"PAY_NOW\",\n"
" payment_method:{\n"
" payee_preferred:\"IMMEDIATE_PAYMENT_REQUIRED\"\n"
" },\n"
" return_url:\"https://Gala.domain.com/cgi-bin/paypal?FZ=4&MF=4&K=SMITH&MR=M&PP=Y\",\n"
" cancel_url:\"https://Gala.domain.com/cgi-bin/paypal?FZ=4&MF=4&K=SMITH&MR=M&PP=C\"\n"
" }\n"
"}";
char* request3 = "{\n"
" \"intent\":\"CAPTURE\",\n"
" \"payer\":{\n"
" \"name\":{\n"
" \"given_name\":\"BOB\",\n"
" \"surname\":\"SMITH\"\n"
" },\n"
" \"email_address\":\"bob#domain.com\",\n"
" \"phone\":{\n"
" \"country_code\":\"011\",\n"
" \"national_number\":\"4162876593\"\n"
" },\n"
" \"address\":{\n"
" \"address_line_1\":\"4180 YONGE STREET\",\n"
" \"admin_area_2\":\"TORONTO\",\n"
" \"admin_area_1\":\"ON\",\n"
" \"postal_code\":\"M1S 2A9\",\n"
" \"country_code\":\"CA\"\n"
" }\n"
" },\n"
" \"purchase_units\":[\n"
" {\n"
" \"amount\":{\n"
" \"currency_code\":\"CAD\",\n"
" \"value\":\"90.00\"\n"
" }\n"
" }\n"
" ],\n"
" \"application_context\":{\n"
" \"brand_name\":\"Benefit Gala\",\n"
" \"landing_page\":\"LOGIN\",\n"
" \"shipping_preference\":\"NO_SHIPPING\",\n"
" \"user_action\":\"PAY_NOW\",\n"
" \"payment_method\":{\n"
" \"payee_preferred\":\"IMMEDIATE_PAYMENT_REQUIRED\"\n"
" },\n"
" \"return_url\":\"https://Gala.domain.com/cgi-bin/paypal?FZ=4&MF=4&K=SMITH&MR=M&PP=Y\",\n"
" \"cancel_url\":\"https://Gala.domain.com/cgi-bin/paypal?FZ=4&MF=4&K=SMITH&MR=M&PP=C\"\n"
" }\n"
"}";
char *request4 = "{\n"
" \"intent\":\"CAPTURE\",\n"
" \"payer\":{\n"
" \"name\":{\n"
" \"given_name\":\"BOB\",\n"
" \"surname\":\"SMITH\"\n"
" },\n"
" \"email_address\":\"bob#domain.com\",\n"
" \"phone\":{\n"
" \"phone_type\":\"HOME\",\n"
" \"phone_number\":{\n"
" \"national_number\":\"4162876593\"\n"
" }\n"
" },\n"
" \"address\":{\n"
" \"address_line_1\":\"4180 YONGE STREET\",\n"
" \"admin_area_2\":\"TORONTO\",\n"
" \"admin_area_1\":\"ON\",\n"
" \"postal_code\":\"M1S 2A9\",\n"
" \"country_code\":\"CA\"\n"
" }\n"
" },\n"
" \"purchase_units\":[\n"
" {\n"
" \"amount\":{\n"
" \"currency_code\":\"CAD\",\n"
" \"value\":\"90.00\"\n"
" }\n"
" }\n"
" ],\n"
" \"application_context\":{\n"
" \"brand_name\":\"Benefit Gala\",\n"
" \"landing_page\":\"LOGIN\",\n"
" \"shipping_preference\":\"NO_SHIPPING\",\n"
" \"user_action\":\"PAY_NOW\",\n"
" \"payment_method\":{\n"
" \"payee_preferred\":\"IMMEDIATE_PAYMENT_REQUIRED\"\n"
" },\n"
" \"return_url\":\"https://Gala.domain.com/cgi-bin/paypal?FZ=4&MF=4&K=SMITH&MR=M&PP=Y\",\n"
" \"cancel_url\":\"https://Gala.domain.com/cgi-bin/paypal?FZ=4&MF=4&K=SMITH&MR=M&PP=C\"\n"
" }\n"
"}";
struct curl_slist *headers=NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "Authorization: Bearer ACCESS_TOKEN_HERE");
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
printf("\n*************************************************************");
printf("\n****************** REQUEST 1 ********************************");
printf("\n*************************************************************\n");
printf("%s\n", request1);
create_order(curl, request1, headers);
printf("\n*************************************************************");
printf("\n****************** REQUEST 2 ********************************");
printf("\n*************************************************************\n");
printf("%s\n", request2);
create_order(curl, request2, headers);
printf("\n*************************************************************");
printf("\n****************** REQUEST 3 ********************************");
printf("\n*************************************************************\n");
printf("%s\n", request3);
create_order(curl, request3, headers);
printf("\n*************************************************************");
printf("\n****************** REQUEST 4 ********************************");
printf("\n*************************************************************\n");
printf("%s\n", request4);
create_order(curl, request4, headers);
}
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
return 0;
}
Output of the test program
*************************************************************
****************** REQUEST 1 ********************************
*************************************************************
{
intent:"CAPTURE",
payer:{
name:{
given_name:"BOB",
surname:"SMITH"
},
email_address:"bob#domain.com",
phone:{
country_code:"011",
national_number:"4162876593"
},
address:{
address_line_1:"4180 YONGE STREET",
admin_area_2:"TORONTO",
admin_area_1:"ON",
postal_code:"M1S 2A9",
country_code:"CA"
}
},
purchase_units:[
{
amount:{
currency_code:"CAD",
value:"90.00"
}
}
],
application_context:{
brand_name:"Benefit Gala",
landing_page:"LOGIN",
shipping_preference:"NO_SHIPPING",
user_action:"PAY_NOW",
payment_method:{
payee_preferred:"IMMEDIATE_PAYMENT_REQUIRED"
},
return_url:"https://Gala.domain.com/cgi-bin/paypal?FZ=4&MF=4&K=SMITH&MR=M&PP=Y",
cancel_url:"https://Gala.domain.com/cgi-bin/paypal?FZ=4&MF=4&K=SMITH&MR=M&PP=C"
}
}
* Trying 151.101.65.35:443...
* Connected to api-m.sandbox.paypal.com (151.101.65.35) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
* CApath: none
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
* Server certificate:
* subject: businessCategory=Private Organization; jurisdictionC=US; jurisdictionST=Delaware; serialNumber=3014267; C=US; ST=California; L=San Jose; O=PayPal, Inc.; CN=www.sandbox.paypal.com
* start date: Jun 2 00:00:00 2021 GMT
* expire date: Mar 24 23:59:59 2022 GMT
* subjectAltName: host "api-m.sandbox.paypal.com" matched cert's "api-m.sandbox.paypal.com"
* issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 Extended Validation Server CA
* SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0xa65310)
> POST /v2/checkout/orders HTTP/2
Host: api-m.sandbox.paypal.com
accept: */*
content-type: application/json
authorization: Bearer REMOVED_ACCESS_TOKEN
content-length: 982
* We are completely uploaded and fine
< HTTP/2 400
< content-type: application/json
< server: nginx/1.14.0 (Ubuntu)
< cache-control: max-age=0, no-cache, no-store, must-revalidate
< paypal-debug-id: f724c871e93df
< strict-transport-security: max-age=31536000; includeSubDomains
< accept-ranges: bytes
< via: 1.1 varnish, 1.1 varnish
< edge-control: max-age=0
< date: Wed, 14 Jul 2021 21:43:56 GMT
< x-served-by: cache-lhr6623-LHR, cache-cdg20728-CDG
< x-cache: MISS, MISS
< x-cache-hits: 0, 0
< x-timer: S1626299036.618323,VS0,VE589
< content-length: 356
<
* Connection #0 to host api-m.sandbox.paypal.com left intact
{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"f724c871e93df","details":[{"location":"body","issue":"MALFORMED_REQUEST_JSON"}],"links":[{"href":"https://developer.paypal.com/docs/api/orders/v2/#error-MALFORMED_REQUEST_JSON","rel":"information_link","encType":"application/json"}]}
******************************** ERROR *********************************
******************************** ERROR *********************************
******************************** ERROR *********************************
*************************************************************
****************** REQUEST 2 ********************************
*************************************************************
{
intent:"CAPTURE",
payer:{
name:{
given_name:"BOB",
surname:"SMITH"
},
email_address:"bob#domain.com",
address:{
address_line_1:"4180 YONGE STREET",
admin_area_2:"TORONTO",
admin_area_1:"ON",
postal_code:"M1S 2A9",
country_code:"CA"
}
},
purchase_units:[
{
amount:{
currency_code:"CAD",
value:"90.00"
}
}
],
application_context:{
brand_name:"Benefit Gala",
landing_page:"LOGIN",
shipping_preference:"NO_SHIPPING",
user_action:"PAY_NOW",
payment_method:{
payee_preferred:"IMMEDIATE_PAYMENT_REQUIRED"
},
return_url:"https://Gala.domain.com/cgi-bin/paypal?FZ=4&MF=4&K=SMITH&MR=M&PP=Y",
cancel_url:"https://Gala.domain.com/cgi-bin/paypal?FZ=4&MF=4&K=SMITH&MR=M&PP=C"
}
}
* Found bundle for host api-m.sandbox.paypal.com: 0xa62db0 [can multiplex]
* Re-using existing connection! (#0) with host api-m.sandbox.paypal.com
* Connected to api-m.sandbox.paypal.com (151.101.65.35) port 443 (#0)
* Using Stream ID: 3 (easy handle 0xa65310)
> POST /v2/checkout/orders HTTP/2
Host: api-m.sandbox.paypal.com
accept: */*
content-type: application/json
authorization: Bearer REMOVED_ACCESS_TOKEN
content-length: 892
* We are completely uploaded and fine
< HTTP/2 400
< content-type: application/json
< server: nginx/1.14.0 (Ubuntu)
< cache-control: max-age=0, no-cache, no-store, must-revalidate
< paypal-debug-id: c7ac50f5fe921
< strict-transport-security: max-age=31536000; includeSubDomains
< accept-ranges: bytes
< via: 1.1 varnish, 1.1 varnish
< edge-control: max-age=0
< date: Wed, 14 Jul 2021 21:43:56 GMT
< x-served-by: cache-lhr7357-LHR, cache-cdg20728-CDG
< x-cache: MISS, MISS
< x-cache-hits: 0, 0
< x-timer: S1626299036.212274,VS0,VE470
< content-length: 356
<
* Connection #0 to host api-m.sandbox.paypal.com left intact
{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"c7ac50f5fe921","details":[{"location":"body","issue":"MALFORMED_REQUEST_JSON"}],"links":[{"href":"https://developer.paypal.com/docs/api/orders/v2/#error-MALFORMED_REQUEST_JSON","rel":"information_link","encType":"application/json"}]}
******************************** ERROR *********************************
******************************** ERROR *********************************
******************************** ERROR *********************************
*************************************************************
****************** REQUEST 3 ********************************
*************************************************************
{
"intent":"CAPTURE",
"payer":{
"name":{
"given_name":"BOB",
"surname":"SMITH"
},
"email_address":"bob#domain.com",
"phone":{
"country_code":"011",
"national_number":"4162876593"
},
"address":{
"address_line_1":"4180 YONGE STREET",
"admin_area_2":"TORONTO",
"admin_area_1":"ON",
"postal_code":"M1S 2A9",
"country_code":"CA"
}
},
"purchase_units":[
{
"amount":{
"currency_code":"CAD",
"value":"90.00"
}
}
],
"application_context":{
"brand_name":"Benefit Gala",
"landing_page":"LOGIN",
"shipping_preference":"NO_SHIPPING",
"user_action":"PAY_NOW",
"payment_method":{
"payee_preferred":"IMMEDIATE_PAYMENT_REQUIRED"
},
"return_url":"https://Gala.domain.com/cgi-bin/paypal?FZ=4&MF=4&K=SMITH&MR=M&PP=Y",
"cancel_url":"https://Gala.domain.com/cgi-bin/paypal?FZ=4&MF=4&K=SMITH&MR=M&PP=C"
}
}
* Found bundle for host api-m.sandbox.paypal.com: 0xa62db0 [can multiplex]
* Re-using existing connection! (#0) with host api-m.sandbox.paypal.com
* Connected to api-m.sandbox.paypal.com (151.101.65.35) port 443 (#0)
* Using Stream ID: 5 (easy handle 0xa65310)
> POST /v2/checkout/orders HTTP/2
Host: api-m.sandbox.paypal.com
accept: */*
content-type: application/json
authorization: Bearer REMOVED_ACCESS_TOKEN
content-length: 1038
* We are completely uploaded and fine
< HTTP/2 400
< content-type: application/json
< server: nginx/1.14.0 (Ubuntu)
< cache-control: max-age=0, no-cache, no-store, must-revalidate
< paypal-debug-id: b52221afefcf6
< strict-transport-security: max-age=31536000; includeSubDomains
< accept-ranges: bytes
< via: 1.1 varnish, 1.1 varnish
< edge-control: max-age=0
< date: Wed, 14 Jul 2021 21:43:57 GMT
< x-served-by: cache-lhr7340-LHR, cache-cdg20728-CDG
< x-cache: MISS, MISS
< x-cache-hits: 0, 0
< x-timer: S1626299037.687787,VS0,VE596
< content-length: 468
<
* Connection #0 to host api-m.sandbox.paypal.com left intact
{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"b52221afefcf6","details":[{"field":"/payer/phone/phone_number","value":"","location":"body","issue":"MISSING_REQUIRED_PARAMETER","description":"A required field / parameter is missing."}],"links":[{"href":"https://developer.paypal.com/docs/api/orders/v2/#error-MISSING_REQUIRED_PARAMETER","rel":"information_link","encType":"application/json"}]}
******************************** ERROR *********************************
******************************** ERROR *********************************
******************************** ERROR *********************************
*************************************************************
****************** REQUEST 4 ********************************
*************************************************************
{
"intent":"CAPTURE",
"payer":{
"name":{
"given_name":"BOB",
"surname":"SMITH"
},
"email_address":"bob#domain.com",
"phone":{
"phone_type":"HOME",
"phone_number":{
"national_number":"4162876593"
}
},
"address":{
"address_line_1":"4180 YONGE STREET",
"admin_area_2":"TORONTO",
"admin_area_1":"ON",
"postal_code":"M1S 2A9",
"country_code":"CA"
}
},
"purchase_units":[
{
"amount":{
"currency_code":"CAD",
"value":"90.00"
}
}
],
"application_context":{
"brand_name":"Benefit Gala",
"landing_page":"LOGIN",
"shipping_preference":"NO_SHIPPING",
"user_action":"PAY_NOW",
"payment_method":{
"payee_preferred":"IMMEDIATE_PAYMENT_REQUIRED"
},
"return_url":"https://Gala.domain.com/cgi-bin/paypal?FZ=4&MF=4&K=SMITH&MR=M&PP=Y",
"cancel_url":"https://Gala.domain.com/cgi-bin/paypal?FZ=4&MF=4&K=SMITH&MR=M&PP=C"
}
}
* Found bundle for host api-m.sandbox.paypal.com: 0xa62db0 [can multiplex]
* Re-using existing connection! (#0) with host api-m.sandbox.paypal.com
* Connected to api-m.sandbox.paypal.com (151.101.65.35) port 443 (#0)
* Using Stream ID: 7 (easy handle 0xa65310)
> POST /v2/checkout/orders HTTP/2
Host: api-m.sandbox.paypal.com
accept: */*
content-type: application/json
authorization: Bearer REMOVED_ACCESS_TOKEN
content-length: 1077
* We are completely uploaded and fine
< HTTP/2 201
< content-type: application/json
< server: nginx/1.14.0 (Ubuntu)
< cache-control: max-age=0, no-cache, no-store, must-revalidate
< paypal-debug-id: 532a3181c034b
< strict-transport-security: max-age=31536000; includeSubDomains
< accept-ranges: bytes
< via: 1.1 varnish, 1.1 varnish
< edge-control: max-age=0
< date: Wed, 14 Jul 2021 21:43:58 GMT
< x-served-by: cache-lhr7357-LHR, cache-cdg20728-CDG
< x-cache: MISS, MISS
< x-cache-hits: 0, 0
< x-timer: S1626299037.296772,VS0,VE954
< content-length: 501
<
* Connection #0 to host api-m.sandbox.paypal.com left intact
{"id":"82447239S1973611B","status":"CREATED","links":[{"href":"https://api.sandbox.paypal.com/v2/checkout/orders/82447239S1973611B","rel":"self","method":"GET"},{"href":"https://www.sandbox.paypal.com/checkoutnow?token=82447239S1973611B","rel":"approve","method":"GET"},{"href":"https://api.sandbox.paypal.com/v2/checkout/orders/82447239S1973611B","rel":"update","method":"PATCH"},{"href":"https://api.sandbox.paypal.com/v2/checkout/orders/82447239S1973611B/capture","rel":"capture","method":"POST"}]}
******************************** SUCCESS *********************************
******************************** SUCCESS *********************************
******************************** SUCCESS *********************************
Mohammed, thanks very much for this !!
The unexpected answer is that the quotes around the field names are required. I have seen many examples where they were not included, and in fact it worked fine without those quotes when the phone number was not specified.
The "phone_type" object is ignored, with HOME specified, the number is still displayed by PayPal as MOBILE, but I can live with that.
Thanks again !!

Wrong Content-Type in response in IErrorHandler

I would like to send response to my service in JSON format. I catch my custom errors in my custom behavior:
void IErrorHandler.ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
XDocument errorMsg = XDocument.Parse("<errorMessage>" + error.Message + "</errorMessage>");
var jsonWriter = new JsonErrorBodyWriter(errorMsg);
fault = Message.CreateMessage(version, null, jsonWriter);
fault.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Json));
HttpResponseMessageProperty prop = new HttpResponseMessageProperty();
prop.StatusCode = HttpStatusCode.Unauthorized;
prop.Headers.Add("Content-Type", "application/json; charset=utf-8");
prop.Headers[HttpRequestHeader.ContentType] = "application/json; charset=utf-8";
--Tried different ways to achieve this
fault.Properties.Add(HttpResponseMessageProperty.Name, prop);
}
But I get wrong content-type in response. And also I couldn't manage to write any custom header like :
prop.Headers.Add("Test", "Value");
Reponse:
HTTP/1.1 401 Unauthorized
Content-Type: application/xml; charset=utf-8
Server: Microsoft-IIS/10.0
X-Powered-By: ASP.NET
Date: Wed, 30 Sep 2020 08:41:15 GMT
Content-Length: 37
{"description":"Autorization Failed"}
What is wrong in my code?

LWP::UserAgent returns incomplete 2GB response message

I am using LWP::UserAgentto send request on a URL. But sometime in the response I am getting incomplete XML response.
Code
$args->{pua} = LWP::UserAgent->new();
$args->{header} = HTTP::Headers->new;
$args->{header}->header("Content-Type" => "text/xml", "SOAPAction" => $args->{soapaction});
$request = HTTP::Request->new( "POST", $args->{endpoint}, $args->{header}, $args->{xml});
$response = $args->{pua}->simple_request($request);
my $xmlResponse = $response->content;
In the $xmlResponse sometime I am getting incomplete response. Why is it happening?
ResponseHeader
Connection: close
Date: Tue, 19 May 2015 11:07:37 GMT
Server: nginx/1.6.2
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Type: text/xml;charset=ISO-8859-1
Client-Date: Tue, 19 May 2015 11:07:40 GMT
Client-Peer: 202.77.98.11:80
Client-Response-Num: 1
Client-Transfer-Encoding: chunked
X-Frame-Options: SAMEORIGIN
LWP may return incomplete response when it failed to read whole body because of the timeout or other read error. In this case $response->is_success will be true and $response->code will be 200, but response headers will contain special header called X-Died.
So you can check this header:
unless ($response->is_success) {
die "Response failed: ", $response->status_line;
}
if ($response->header('X-Died')) {
die "Response failed (internal): ", $response->header('X-Died');
}

Twitter 403 error for update_with_media everytime

I am using MGTwitterEngine, and I am using update_with_media api call for posting status as well as image. It works some times but now it is giving me error message with error code 403.
I am getting message from twitter,
equest A281E76C-889C-4E79-B8CE-B8D9B89CAD5D failed with error: Error Domain=HTTP Code=403 "The operation couldn’t be completed. (HTTP error 403.)"
headers for failed response: {
"Cache-Control" = "no-cache, no-store, must-revalidate, pre-check=0, post-check=0";
Connection = "Keep-Alive";
"Content-Encoding" = gzip;
"Content-Length" = 146;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Wed, 09 May 2012 13:59:18 GMT";
Expires = "Tue, 31 Mar 1981 05:00:00 GMT";
"Keep-Alive" = "timeout=15, max=100";
"Last-Modified" = "Wed, 09 May 2012 13:59:17 GMT";
Pragma = "no-cache";
Server = hi;
"Set-Cookie" = "k=121.242.223.26.1336571957410684; path=/; expires=Wed, 16-May-12 13:59:17 GMT; domain=.twitter.com, guest_id=v1%3A133657195794826993; domain=.twitter.com; path=/; expires=Sat, 10-May-2014 01:59:17 GMT, dnt=; domain=.twitter.com; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT, lang=en; path=/, lang=en; path=/, lang=en; path=/, lang=en; path=/, twid=u%3D309516512%7Ccj5mm3XKJjrOylGjj9dBeiIYQXM%3D; domain=.twitter.com; path=/; secure, _twitter_sess=BAh7CToPY3JlYXRlZF9hdGwrCMWS5TE3AToHaWQiJWIxYTFiNjkyYWFhMzA4%250AN2E3MDZlZmY0MWE4MmZlMDgzIgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVy%250AOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsAOgxjc3JmX2lkIiUzNzg5%250AOGJhN2Q4M2MzY2NkODZiYmI0OGI1MjFkMzI3Ng%253D%253D--d5860bbfc91c1a86b279feeb0a5f6a902809c18a; domain=.twitter.com; path=/; HttpOnly";
Status = "403 Forbidden";
Vary = "Accept-Encoding";
"X-Access-Level" = "read-write";
"X-Action-Name" = "update_with_media";
"X-Controller-Class" = "Api::StatusController";
"X-Frame-Options" = SAMEORIGIN;
"X-MID" = 10eaf9e95fb949887d309c590873aa70188770d4;
"X-MediaRateLimit-Class" = photos;
"X-MediaRateLimit-Limit" = 30;
"X-MediaRateLimit-Remaining" = 30;
"X-MediaRateLimit-Reset" = 1336658357;
"X-Runtime" = "0.07889";
"X-Transaction" = ecd0661ac173c9ab;
"X-Transaction-Mask" = a6183ffa5f8ca943ff1b53b5644ef1141757cb62;
}
I am not getting what should be done in this case.
In twitter documentation 403 error is for duplicate tweet, but I am tweeting for the first time.
Thank you in advance.

SOAP servers and clients with Zend framework (Getting errors)

I am testing a server and client i made on my webspace.
when i try to call a simple "testServer" function defined in a ServerMap class, I get
"Looks like we got no XML document"
..?
I called getFunctions on the client and testServer is a valid function. I tried catching all exceptions and then calling __getLastResponseHeaders() and __getLastResponse.
header:
string(348) "HTTP/1.1 200 OK
Date: Tue, 23 Jun 2009 19:36:29 GMT
Server: Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.9
X-Powered-By: PHP/5.2.9
Cache-Control: max-age=1
Expires: Tue, 23 Jun 2009 19:36:30 GMT
Vary: Accept-Encoding
Content-Length: 1574
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
"
response:
string(1574) "DEBUG HEADER : This is a cached page !
"
If i look at the source html of the response, its actually:
string(1574) "DEBUG HEADER : This is a cached page !<?xml version="1.0"?>
<A lot of xml that looks pretty much like my WSDL file that my Zend_Soap_AutoDiscover generates>
So whats going on? I searched online and i didnt really find any solid solutions.
I don't have blank space before my ..
If you are outputting to the browser, it is hiding the xml cause it is in a . Browsers ignore tags they don't understad.
Do a echo htmlentities($output); to see the xml tags.
Not sure what your problem is, but I can provide a bit of code that I know works for us using Zend Framework 1.8x as a backend SOAP service for silverlight and WCF. This service simples takes 2 integers, adds them and returns the result. Simple as you can get.
Controller Class example:
class SoapController extends Zend_Controller_Action {
/*
* SOAP server action
*/
public function indexAction() {
$request = $this->getRequest();
if ($request->getParam('wsdl') !== null) {
$wsdl = new Zend_Soap_AutoDiscover();
$wsdl->setClass('SoapMath');
$wsdl->handle();
}
else {
$module = $request->getModuleName();
$controller = $request->getControllerName();
$uri = 'http://' . Zend_Registry::get('fullUrl') . '/' . $module . '/' . $controller . '?wsdl';
$server = new Zend_Soap_Server($uri);
$server->setClass('SoapMath');
$server->handle();
}
exit;
}
}
And the actual work is done by 'SoapMath' which is defined as:
class SoapMath {
public function add($a,$b) {
return ($a + $b);
}
}