Attributes not visible when sending message to Amazon SQS using PHP SDK - php

I am trying to send a message to an SQS queue, in PHP with a message body and message attributes. This is how my message looks:
$message = [
'MessageAttributes' => [
"Title" => [
'DataType' => "String",
'StringValue' => "The Hitchhiker's Guide to the Galaxy"
],
"Author" => [
'DataType' => "String",
'StringValue' => "Douglas Adams."
],
"WeeksOn" => [
'DataType' => "Number",
'StringValue' => "6"
]
],
'QueueUrl' => $this->queueUrl,
'MessageBody' => 'Hello SQS testing'
];
I found this example on Github: Sending and Receiving Messages in Amazon SQS.
When I open the console and look for my message in the queue, I can see the message body but I don't see any attributes. I am using Amazon SDK for PHP 3.x.

Related

Paypal / field missing when I try to capture a multiseller payment

Here is the response, I don't urdestand what is the problem.
{
"name": "INVALID_REQUEST",
"message": "Request is not well-formed, syntactically incorrect, or violates schema.",
"debug_id": "5939e86ea6f6e",
"details": [
{
"field": "/",
"location": "body",
"issue": "MALFORMED_REQUEST_JSON",
"description": "The request JSON is not well formed."
}
],
"links": [
{
"href": "https://developer.paypal.com/docs/api/orders/v2/#error-MALFORMED_REQUEST_JSON",
"rel": "information_link",
"encType": "application/json"
}
]
}
And the code, what calls the capture endpoint:
$headerForBasicAuth = $this->paypalModel->getBasicAuthHeader();
$http = Http::withHeaders([
'Authorization' => 'Basic '.$headerForBasicAuth,
'Content-Type' => 'application/json'
]);
$response = $http->post($this->paypalModel->getBasePath().'/v2/checkout/orders/'.$request->orderID.'/capture')->body();
If needed, there is the code, how I create the order:
$headerForBasicAuth = $this->paypalModel->getBasicAuthHeader();
$http = Http::withHeaders([
'Authorization' => 'Basic '.$headerForBasicAuth,
'Content-Type' => 'application/json'
]);
$body = [
'intent' => "CAPTURE",
'purchase_units' => [
[
'payee' => [
"merchant_id" => "V2B4REMFCWFE6"
],
'amount' => [
'currency_code' => 'USD',
//'value' => $data['price']
'value' => '15'
],
'payment_instruction' => [
'disbursement_mode' => 'INSTANT',
'platform_fees' => [
[
'amount' => [
'currency_code' => 'USD',
'value' => '5'
]
]
]
]
]
],
'application_context' => [
'cancel_url' => 'http://laravel-paypal-example.test',
'return_url' => 'http://laravel-paypal-example.test',
'shipping_preference' => 'NO_SHIPPING'
]
];
$response = $http->post($this->paypalModel->getBasePath().'/v2/checkout/orders', $body)->body();
I'm using platform fee, but in admin menu, I can't enable the platform fees checkbox, every time give an error: "Your settings weren't saved. Please try again later."
The orderID is okay, I checked many times. So, when I create an order, I can accept the payment in the PayPal checkout, but when the transaction is approved, I can't capture it with orderID.
Somehow there is a request body in what you are posting to the /capture endpoint. From looking at your code I can't tell how/why a body is being added, but it is in fact being added, and whatever is added is not valid JSON, and hence the request is rejected.

Push notification with pusher beam, unable to send data/payload

I am using following php sdk for generating pusher beam push notification. but there is not information provided in the sdk docs on how to send data/payload along with it. the notification is bean sent correctly but I am unable to send data: please guide me how we can send the data: it is showing hasData as false in beam console, please check:
php sdk i am using : https://github.com/pusher/push-notifications-php
my code look like this:
$pushNotification = new PushNotifications([
'instanceId' => env('BEAM_INSTANCE_ID'),
'secretKey' => env('BEAM_PRIMARY_KEY')
]);
$pushNotification->publishToInterests(
['message-notification'],
[
"apns" => [
"aps" => [
"alert" => "Message Received",
],
],
"fcm" => [
"notification" => [
'title' => 'some title',
'body' => 'some body',
'data' => 'some data', //passing data here but not working
],
],
]
);
I got it working, we can pass data in following way:
$publishResponse = $pushNotifications->publishToInterests(
["donuts"],
[
"apns" => [
"aps" => [
"alert" => "Hello!",
],
],
"fcm" => [
"notification" => [
"title" => "Hello!",
"body" => "Hello, world!",
],
"data" => [ // <==== pass data here
"name" => "adam",
"type" => "user",
],
],
]
);

Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true in lumen with elastic search 7.6.2

I am using https://github.com/basemkhirat/elasticsearch package.
In es.php file i have below indices
'indices' => [
'media' => [
'settings' => [
'number_of_shards' => 2,
'number_of_replicas' => 2,
'analysis' => [
'filter' => [
'custom_english_stemmer' => [
'type' => "stemmer",
'name' => "english"
],
"english_stop" => [
'type' => "stop",
'stopwords' => "_english_"
]
],
"analyzer" => [
'custom_lowercase_analyzer' => [
// 'type' => 'custom',
'tokenizer' => 'standard',
'filter' => [
'lowercase',
'english_stop',
"custom_english_stemmer"
]
]
]
]
],
'mappings' => [
'properties' => [
'id' => [
'type' => 'long',
'index' => false,
'doc_values' => false,
],
'title' => [
'type' => 'text',
"analyzer" => 'custom_lowercase_analyzer'
]
]
]
]
]
Now when php artisan es:indices:create is executed settings is created but mapping fails with an error message.
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."
}
],
"type": "illegal_argument_exception",
"reason": "Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."
},
"status": 400
}
How to fix this issue
You are providing type in your create index code, remove media type from your index, as types are deprecated, see the removal of types for more information.
Please note in Elasticsearch 7.X still you can do some workaround to have custom types by having include_type_name param but it's not preferred as types will be totally removed in upcoming Elasticsearch 8.X.
In order to use create your index with custom type like media(default is _doc mentioned in your screen-shot) in your case, you need to pass include_type_name=true to index creation, template, and mappings APIs as mentioned in this official ES blog

FCM link not working in desktop notification

We are trying to send a desktop notification calling the FCM rest api via a php service.
We call the https://fcm.googleapis.com/fcm/send service, passing the following payload:
"data" => [
"notification" => [
"title" => $content->title,
"body" => "notification body",
"icon" => url('assets/images/logo_3.png'),
],
"webpush" => [
"headers" => [
"Urgency" => "high",
],
"fcm_options" => [
"link" => url($content->url)
]
],
],
The notification is received in desktop (tested on windows 10) but when we click on the popup the link is not opened in the browser.
What are we doing wrong?
It turns out that we must use click_action field, like this:
"notification" => [
"title" => $content->title,
"body" => "body",
"icon" => "assets/icon.png",
"click_action" => "https://www.example.com",
]
Docs here:https://firebase.google.com/docs/cloud-messaging/http-server-ref

Proper syntax for AWS S3 php-sdk "putObjectAcl"

I've been tasked with figuring out how the AWS PHP sdk works so we can possibly use it for hosting customer image data for our web server. I've been able to successfully test most of the functionality of creating, managing and loading data into a bucket, but when I try to view the contents I get 'access denied'.
Going into the management console, I figured out how to set the permissions so I could view the file, either with a specific host rule or by setting both the bucket and the object world-readable.
However, no matter how I try following the examples in the PHP sdk [limited] documentation, I cannot seem to set the ACL values using the php code provided by Amazon.
Their examples just list in the place of the various value and I have tried filling in the relevant data for my bucket, object and account in those and it doesn't work. I've tried doing a getObjectAcl and sending back something similar to what was received and it doesn't work. I've tried looking at examples on-line and what little I have found doesn't work.
Here's an example of the latest I have tried:
$params = [
'ACL' => 'public-read',
'AccessControlPolicy' => [
'Grants' => [
[
'Grantee' => [
'DisplayName' => 'Owner',
'ID' => $awsId,
'Type' => "CanonicalUser"
],
'Permission' => "FULL_CONTROL"
],
[
'Grantee' => [
'DisplayName' => 'All Users',
'URI' => "http://acs.amazonaws.com/groups/global/AllUsers",
'Type' => "Group"
],
'Permission' => "READ"
],
],
'Owner' => [
'ID' => $awsId
]
],
'Bucket' => "our-test-bucket",
'Key' => "800x600.jpg"
];
$result = $awsSdk->getS3Client()->putObjectAcl($params);
The resulting output:
Fatal error: Uncaught exception 'Aws\S3\Exception\S3Exception' with
message 'Error executing "PutObjectAcl" on
"https://our-test-bucket.s3.us-east-2.amazonaws.com/800x600.jpg?acl";
AWS HTTP error: Client error: PUT
https://our-test-bucket.s3.us-east-2.amazonaws.com/800x600.jpg?acl
resulted in /project/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php
on line 191
Aws\S3\Exception\S3Exception: Error executing "PutObjectAcl" on "https://our-test-bucket.s3.us-east-2.amazonaws.com/800x600.jpg?acl";
AWS HTTP error: Client error: PUT
https://our-test-bucket.s3.us-east-2.amazonaws.com/800x600.jpg?acl
resulted in a 400 Bad Request response:
MalformedACLErrorThe XML you provided was not well-f (truncated...)
MalformedACLError (client): The XML you provided was not well-formed or did not validate against our published schema -
MalformedACLErrorThe XML you provided was not well-formed or did not validate against our published
schemaB24661919936C2DADft/***********************************************= in /project/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line
191
I managed to drop a trace into the guzzle html messageTrait withHeader() function so I could watch the outgoing xml in the php stream. I then compared the result with examples of the xml I found in various places in a google search and through trial and error with the comparisons, I traced the problem down to the 'DisplayName' => 'All Users' in the Group Grant. Remove that line and it appears to work.
$pubAcl = [
'Owner' => [
'ID' => $awsId,
'DisplayName' => 'Owner'
],
'Grants' => [
[
'Grantee' => [
'ID' => $awsId,
'DisplayName' => 'Owner',
'Type' => "CanonicalUser"
],
'Permission' => "FULL_CONTROL"
],
[
'Grantee' => [
'URI' => "http://acs.amazonaws.com/groups/global/AllUsers",
'Type' => "Group"
],
'Permission' => "READ"
]
]
];
(The order change was the result of testing but didn't turn out to be the problem)

Categories