Using the Chronopost Web Services.
When using this post HTTP request in a web browser (account number and password are hidden there, so you can't test yourself unless you have a Chronopost ID) :
https://ws.chronopost.fr/shipping-cxf/ShippingServiceWS/shippingWithReservationAndESDWithRefClientPC?subAccount=000&accountNumber=ACCOUNT_NUMBER&password=PASSWORD&shipperCivility=E&shipperName=DELBET&shipperName2=RICHARD&shipperAdress1=1%20rue%20des%20accents&shipperZipCode=28500&shipperCity=Ste%20Gemme%20Moronval&shipperCountry=FR&shipperCountryName=France&shipperContactName=Richard%20Delbet&shipperEmail=richard.delbet#telintrans.fr&shipperPhone=0123456789&shipperMobilePhone=0601020304&recipientCivility=E&recipientName=MALKA&recipientName2=DAVID&recipientAdress1=1%20rue%20des%20essais&recipientZipCode=75001&recipientCity=Paris&recipientCountry=FR&recipientCountryName=France&recipientContactName=David%20Malka&recipientEmail=david.malka#telintrans.fr&recipientPhone=0222426789&recipientMobilePhone=0622220304&shipperRef=CMD1&recipientRef=ART1&productCode=01&shipDate=27/07/2010%2010:00:00&shipHour=10&weight=2&service=0&objectType=MAR&modeRetour=1&mode=PDF
I have a valid response with all the correct datas.
When using SoapClient with exactly the same parameters :
$client = new \SoapClient("http://ws.chronopost.fr/shipping-cxf/ShippingServiceWS?wsdl");
$data = [
'subAccount' => '000',
'accountNumber' => ACCOUNT_NUMBER,
'password' => PASSWORD,
'shipperCivility' => 'E',
'shipperName' => 'DELBET',
'shipperName2' => 'RICHARD',
'shipperAdress1' => '1%20rue%20des%20accents',
'shipperZipCode' => '28500',
'shipperCity' => 'Ste%20Gemme%20Moronval',
'shipperCountry' => 'FR',
'shipperCountryName' => 'France',
'shipperContactName' => 'Richard%20Delbet',
'shipperEmail' => 'richard.delbet#telintrans.fr',
'shipperPhone' => '0123456789',
'shipperMobilePhone' => '0601020304',
'recipientCivility' => 'E',
'recipientName' => 'MALKA',
'recipientName2' => 'DAVID',
'recipientAdress1' => '1%20rue%20des%20essais',
'recipientZipCode' => '75001',
'recipientCity' => 'Paris',
'recipientCountry' => 'FR',
'recipientCountryName' => 'France',
'recipientContactName' => 'David%20Malka',
'recipientEmail' => 'david.malka#telintrans.fr',
'recipientPhone' => '0222426789',
'recipientMobilePhone' => '0622220304',
'shipperRef' => 'CMD1',
'recipientRef' => 'ART1',
'productCode' => '01',
'shipDate' => '27/07/2010%2010:00:00',
'shipHour' => '10',
'weight' => '2',
'service' => '0',
'objectType' => 'MAR',
'modeRetour' => '1',
'mode' => 'PDF',
];
$response = $client->__soapCall("shippingWithReservationAndESDWithRefClientPC", array($data));
I have an error returned :
object(stdClass)#531 (1) { ["return"]=> object(stdClass)#537 (2) {
["errorCode"]=>
int(1)
["errorMessage"]=>
string(3112) " fr.chronopost.soap.shipping.exception.ValidateException at
fr.chronopost.soap.shipping.util.PopulateUtils.populateSkybill(PopulateUtils.java:355)
at
fr.chronopost.soap.shipping.cxf.ShippingServiceWS.shippingWithReservationAndESDWithRefClientPC(ShippingServiceWS.java:615)
at sun.reflect.GeneratedMethodAccessor1258.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606) at
org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:136)
at
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:82)
at
org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:54)
at
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:68)
at
org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:56)
at
org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
at
org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:92)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
at
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:78)
at
org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:92)
at
org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:285)
at
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:168)
at
org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:175)
at
org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCXFServlet.java:153)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at
org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
at
org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:776)
at
org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:705)
at
org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:898)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
at java.lang.Thread.run(Thread.java:744) " } }
Unfortunately, the error code "1" is described in the documentation as "system error".
One proabably can't help me directly about the Chronopost Web Services, but maybe I'm missing something into the PHP SoapClient object.
Why do I have a correct response when using a web browser and some kind of ValidateException error when using SoapClient ?
When making a SOAP call, you don't need to include URL encoded data strings. Php soapclient encodes the data into XML automatically. So the problem is most likely the validation the service is performing on your data, and it's choking on the % characters. Try changing
'shipDate' => '27/07/2010%2010:00:00'
to
'shipDate' => '27/07/2010 10:00:00'
Related
I am trying to get Polly to read something for me, using PHP.
I have created a new project, installed Amazon composer require aws/aws-sdk-php and then created a file with code from SDK documentation example and modified a few minor things such as changing credential from default to value, var_dump to var_export and finally saved the content of the stream to file
<?php
require 'vendor/autoload.php';
use Aws\Exception\AwsException;
use Aws\Polly\PollyClient;
use Aws\Credentials\Credentials;
// Create a PollyClient
$client = new Aws\Polly\PollyClient([
//'profile' => 'default',
'credentials' => new Credentials('XXXXXXXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'),
'version' => '2016-06-10',
'region' => 'us-east-2'
]);
try {
$result = $client->synthesizeSpeech([
'Text' => 'Hello',
'OutputFormat' => 'json', //json|mp3|ogg_vorbis|pcm
'VoiceId' => 'Joanna',
]);
var_export($result);
$data = $result->get('AudioStream')->getContents();
echo "\n\n";
var_export($data);
$file = fopen('test.txt','w+');
fwrite($file,$data);
fclose($file);
} catch (AwsException $e) {
echo $e->getMessage() . "\n";
}
The result I'm getting is following
Aws\Result::__set_state(array(
'data' => array (
'AudioStream' => GuzzleHttp\Psr7\Stream::__set_state(array(
'stream' => NULL,
'size' => NULL,
'seekable' => true,
'readable' => true,
'writable' => true,
'uri' => 'php://temp',
'customMetadata' => array (),
)),
'ContentType' => 'application/x-json-stream',
'RequestCharacters' => '5',
'#metadata' => array (
'statusCode' => 200,
'effectiveUri' => 'https://polly.us-east-2.amazonaws.com/v1/speech',
'headers' => array (
'x-amzn-requestid' => 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
'x-amzn-requestcharacters' => '5',
'content-type' => 'application/x-json-stream',
'transfer-encoding' => 'chunked',
'date' => 'Sat, 18 Sep 2021 05:11:20 GMT',
),
'transferStats' => array (
'http' => array (
0 => array (),
),
),
),
),
'monitoringEvents' => array (),
))
''
As you can see the size of the AudioStream is null (nothing in it) and also the created file is also empty since there is nothing in the stream to read.
If I change a credential to an invalid string, I get errors, and with the valid credential, the status code is 200, which makes me believe that my request is successful.
I changed voiceId to any other valid or invalid id and even changed the region with others with valid values getting status 200 and with invalid ones getting error messages, but I'm still not getting anything out of polly, it doesn't feel like talking!
Note: When I run $arr_voices = $polly->describeVoices();, I can read list of the voices without error.
Note: I had the same issue with .NET SDK too, which makes me think either there is something wrong with my request or some error message is missing from API.
Question
What I'm doing wrong?
You're not doing anything wrong, but it only outputs JSON if you're looking for speech marks. Try switching to an audio output format like MP3 as shown below.
$result = $client->synthesizeSpeech([
'Text' => 'Hello',
'OutputFormat' => 'mp3', //json|mp3|ogg_vorbis|pcm
'VoiceId' => 'Joanna',
]);
If you're looking for speech marks- metadata on the speech that will be synthesized- you need to specify SpeechMarkTypes as shown here https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-polly-2016-06-10.html#synthesizespeech
I'm trying to create this XML in a SOAP call
<ns1:NameID type="INTERNAL">831392</ns1:NameID>
<ns1:NameMembership primary="true" displaySequence="1">
<ns2:membershipType>PFS</ns2:membershipType>
<ns2:membershipNumber>222222E</ns2:membershipNumber>
<ns2:membershipLevel>SILVER</ns2:membershipLevel>
<ns2:memberName>Luis Fernandez </ns2:memberName>
</ns1:NameMembership>
I don't know how to add the primarykey and displaySequence` attributes. I trying to create something like this:
$parameters = array("NameID" => array("_" => "831392", "type" => "INTERNAL"),
"NameMembership" => array("_" => array(
"membershipLevel" => "SILVER",
"memberName" => "Luis Fernandez",
"membershipType" => "PFS",
"membershipNumber" => "222222E"), "primary" => true, "displaySequence" => 1
));
But it doesn't work. It returns this code:
<ns1:InsertGuestCardRequest>
<ns1:NameID type="INTERNAL">831392</ns1:NameID>
<ns1:NameMembership primary="true" displaySequence="1"/>
</ns1:InsertGuestCardRequest>
Can anyone help me to find what am I doing wrong?
I got it! Thanks!
$parameters = array("NameID" => array("_" => "831392", "type" => "INTERNAL"),
"NameMembership" => array(
"membershipLevel" => "SILVER",
"memberName" => "Luis Fernandez",
"membershipType" => "PFS",
"membershipNumber" => "222222E",
"primary" => true,
"displaySequence" => 1
));
I'm new to web dev and I'm experimenting with Braintree webhooks. I'm using their create submerchant example code to create a submerchant and then supposedly a notification is supposed to reach my server that says if it was successful or not.
My method: I refresh the submerchant.php page (I'm using Wordpress on a NameCheap server), which then echo's "Success!". Then I go to the webhooks.php page and refresh it. However, the var_dump's only return NULL NULL and the print_r's don't return anything. Why does print_r not show anything?
submerchant.php - this creates the submerchant when I set $one = 1 and set a new id for the submerchant
<?php
require_once(__DIR__ . '/../braintree/lib/Braintree.php');
Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('A');
Braintree_Configuration::publicKey('B');
Braintree_Configuration::privateKey('C');
function fd_create_sm() {
$one;
$one = 1;
if($one=1) {
$merchantAccountParams = [
'individual' => [
'firstName' => 'Janez',
'lastName' => 'Doe',
'email' => 'jane#14ladders.com',
'phone' => '5553334444',
'dateOfBirth' => '1981-11-19',
'ssn' => '456-45-4567',
'address' => [
'streetAddress' => '111 Main St',
'locality' => 'Chicago',
'region' => 'IL',
'postalCode' => '60622'
]
],
'business' => [
'legalName' => 'Jane\'s Ladders',
'dbaName' => 'Jane\'s Ladders',
'taxId' => '98-7654321',
'address' => [
'streetAddress' => '111 Main St',
'locality' => 'Chicago',
'region' => 'IL',
'postalCode' => '60622'
]
],
'funding' => [
'descriptor' => 'Red Ladders',
'destination' => Braintree_MerchantAccount::FUNDING_DESTINATION_BANK,
'email' => 'funding#blueladders.com',
'mobilePhone' => '5555555555',
'accountNumber' => '1123581321',
'routingNumber' => '071101307'
],
'tosAccepted' => true,
'masterMerchantAccountId' => "na",
'id' => "green_ladders"
];
$result = Braintree_MerchantAccount::create($merchantAccountParams);
$result->success;
if($result->success) {
echo 'Success!';
} else {
print_r($result->errors);
$errordata;
echo '***********';
$BT_Errors = new Braintree_Error_ErrorCollection($errordata);
echo '***********';
$BT_Errors->deepAll();
echo '***********';
$BT_Errors->onHtmlField("transaction[amount]");
}
$result->merchantAccount->status;
$result->merchantAccount->id;
// "blue_ladders_store"
$result->merchantAccount->masterMerchantAccount->id;
// "14ladders_marketplace"
$result->merchantAccount->masterMerchantAccount->status;
// "active"
} else {
return;
}
}
fd_create_sm();
?>
webhooks.php
<?php
var_dump($_POST['bt_signature']);
var_dump($_POST['bt_payload']);
print_r($_POST['bt_signature']);
print_r($_POST['bt_payload']);
?>
Most likely, the outputted data is stored within some output buffer. If you're pretty sure you want to debug your code this way, try adding wp_die(); call right after you output data using print_r. That should help!
One more thing: sometimes some of the code (not this particular case) is actually never outputted due to more complex data flow. For this cases it might be a good idea to use some 3-rd party debugging tools or, if you're looking for simpler solution, you can write some of the output to some log file, and check the file afterwards.
Good Luck!
add die; after last line of print_r()
The script is allocating an IP but I'm not seeing the security rule in the GUI. No errors are being thrown. Here is the code snippet I am using:
$config = aws_setup();
$ec2Client = \Aws\Ec2\Ec2Client::factory($config);
$gmodel = $ec2Client->allocateAddress();
$args = array('GroupName' => 'www', 'IpPermissions' => array(array('IpProtocol' => 'tcp', 'FromPort' => 22, 'ToPort' => 22)), 'IpRanges' => array('CidrIp' => array($gmodel->get('PublicIp') . '/32')));
$ec2Client->authorizeSecurityGroupIngress($args);
Got the right syntax for the 'args' variable:
$args = array('GroupName' => 'www', 'IpPermissions' => array(array('IpProtocol' => 'tcp', 'FromPort' => 22, 'ToPort' => 22, 'IpRanges' => array(array('CidrIp' => $gmodel->get('PublicIp') . '/32')))));
The rule is now being added to the security group.
I'm having a recurring issue with PHP's inbuilt SOAP client where it returns the same error response regardless of the input paramaters.
Is there an advantage to using the SOAP library built into PHP or a disadvantage to directly querying via cURL through GET?
$client = new SoapClient("http://example.com/wdsl");
$params = array(
'Username' => 'username',
'Password' => 'pass',
'EventName' => 'Test Event',
'EventDate' => '2011-06-15T13:45:30',
'Destination' => '447987654321',
'Carrier' => '1',
'PhoneType' => '13',
'Originator' => 'ukflive',
'MessageText' => 'Test',
'LogoURL' => 'http://example.com/mail.gif',
'BookingReference' => '123456',
'Tickets' => '1',
'CollectionValidFrom' => '2011-06-15T13:45:30',
'CollectionValidTo' => '2011-06-15T18:45:30',
'TemplatePath' => '',
'PostBack' => 'http://example.com/'
);
$response = $client->__soapCall("SendManagedMobileTicket", $params);
print_r($response);
SoapClient is an integrated, actively maintained part of PHP5. cURL is the quick and dirty way to send HTTP data. The smart long term decision is to stick with SoapClient and its methods.
You may also want to look into the response headers, as shown in the notes section of the __soapCall() documentation page: http://www.php.net/manual/en/soapclient.soapcall.php#102387