Ionic 2 - FCM custom sound notification - ionic-framework

I have implemented FCM notification using PHP to send notification on mobile.
Notification working properly but I want to add sound to the notification.
I followed Ionic documentation for FCM.
this.fcm.getToken().then(token =>{
alert("token : "+token);
});
this.fcm.onNotification().subscribe(data => {
alert("data :"+ JSON.stringify(data));
if(data.wasTapped){
alert("Received in background : "+ JSON.stringify(data.msg));
} else {
alert("Received in foreground : "+ JSON.stringify(data.msg));
}
}, err =>{
alert("Received err : "+ err);
})
My php payload:
$message['msg'] = 'notification text';
$message['sound'] = 1;
$message['vibrate'] = 1;
$fields = array(
'registration_ids' => $tokenIds,
'data' => array('message' => $message)
);
i'm sending $fields to notification plugin
Did anyone implement this kind of functionality?

In your push notification payload set following properties.
You need to set sound property to default
"notification":{
"title":"Notification title",
"body":"Notification body",
"sound":"default",
"click_action":"FCM_PLUGIN_ACTIVITY",
"icon":"fcm_push_icon"
},

At php server side i have set $fields array like this
$fields = array(
'registration_ids' => $tokenIds,
'data' => array('message' => $message,
'click_action' => "FCM_PLUGIN_ACTIVITY",
'sound'=>'default'),
'notification'=>array('message' => $message,
'click_action' => "FCM_PLUGIN_ACTIVITY",
'sound'=>'default'),
'priority'=> "high"
);
this can work for fcm notification at background and for sound in ionic

Related

PayPal Smart Payment Buttons - Alternative Payment Methods - 400 Bad Request

I'm using the PayPal Smart Payment Buttons on my website to capture payments.
The Order is created server-side via the PayPal-checkout-sdk for PHP.
$request = new OrdersCreateRequest();
$request->prefer('return=representation');
$request->body = self::buildRequestBody($paymentAC);
// 3. Call PayPal to set up a transaction
$client = PayPalClient::client();
$response = $client->execute($request);
The request body looks like this:
return array(
'intent' => 'CAPTURE',
'commit' => true,
'application_context' =>
array(
'brand_name' => 'EXAMPLE INC',
'locale' => 'de-DE'
'shipping_preference' => 'NO_SHIPPING'
),
'purchase_units' =>
array(
0 =>
array(
'reference_id' => $rId,
'description' => 'Ihr kauf bei EXAMPLE INC',
'invoice_id' => $paymentAC,
'amount' =>
array(
'currency_code' => $currency, #EUR
'value' => $price,
'breakdown' =>
array(
'item_total' =>
array(
'currency_code' => $currency,
'value' => $itemTotal,
),
'tax_total' =>
array(
'currency_code' => $currency,
'value' => 0,
),
),
),
'items' => $items,
),
),
);
The request works fine and an order is created. The script returns a JSON Object with the "id" key set to the ID of the created order.
{"id": "PAYMENTID"}
The script is called by the payment button like this:
paypal.Buttons({
createOrder: function() {
return fetch('./CreateOrder.php', {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: '{"payment_ac": "<?php echo $_GET['code'] ?>"}'
}).then(function(res) {
console.log(res);
return res.json();
}).then(function(data) {
return data.id; // Use the key sent by your server's response, ex. 'id' or 'token'
});
},
onError: (err) => {
console.error('error from the onError callback', err);
},
onApprove: function(data, actions) {
// This function captures the funds from the transaction.
$("#loadMe").modal({
backdrop: "static", //remove ability to close modal with click
keyboard: false, //remove option to close with keyboard
show: true //Display loader!
});
return actions.order.capture().then(function(details) {
// This function shows a transaction success message to your buyer.
console.log(details);
//window.location.href = "verify.php?id=" + data.orderID + "&ac=<?php echo $internalID ?>";
$.get({
url: "/payment/verify.php?id=" + data.orderID + "&ac=<?php echo $internalID ?>",
success: function (respdata) {
if (respdata['payment'] === "completed") {
window.location.href = '/success/<?php echo $internalID?>&cid=' + respdata['cid'];
} else {
alert(respdata);
}
}
})
});
},
onCancel: function (data) {
console.log(data);
alert(data);
// Show a cancel page, or return to cart
window.location.href = "/payment/cancelled.php?ac=<?php echo $internalID ?>&oid=" + data.orderID;
},
style: {
color: 'black',
label: 'pay',
layout: 'vertical'
}
}).render('#paypal-button-container');
The payment buttons can open the checkout window successfully.
When I'm using sandbox credentials everything works fine. (PayPal, Simulated Alternative Payments & Credit Card payments)
When I'm switching to live credentials only PayPal payments seem to work. Every alternative payment method redirects to https://www.paypal.com/latinumcheckout/error/generic-error after you enter your details on https://www.paypal.com/latinumcheckout/change-userinfo
When in the developer console there is an error output:
the server responded with a status of 400 () app.bundle.js:41:140543
Credit card payments seem to fail as well.
I'm clueless, I spent a long time reading the documentation but have found no solution.

notification received on background dose not trigger pushObject.on('notification'). when app is clised too

i use php to send notification to ionic app , the pushObject.on('notification') is executed only when app is runing but when app is on background or closed , clicking on the notification dose only open the app and my pushObject.on('notification'). is not called.
i have already made a lot of payload version as searching as in the solution
phonegap-plugin-push on("notification") event is not firing when app is in background
my php code is
<?php
#API access key from Google API's Console
define( 'API_ACCESS_KEY', 'xxxxxxx' );
#prep the bundle
$msg = array
(
"notId"=> "test",
"body"=> "test",
"title"=> "Cabinet sahli : قرار جديد",
"vibrate"=> 1,
"sound"=>"default",
"case_number"=> "test",
"case_title"=>"test",
"case_id"=> 13,
"content-available"=> 1,
"priority"=> "high",
"additionalData"=> [
"surveyID" => "ewtawgreg-gragrag-rgarhthgbad",
]
);
$fields = array
(
//'registration_ids' => array('d7pT_z1pwYo:APA91bFK2KilUzZon1g4Yu5-bZgaqxeepcP0Owzn2a6QgGuK4HUsI-hQhRbAYANIYfl3xdDYq-k6lAsnNSFyRB4qgEH1wJqDRw6V4s3kKpg_OZHT4UZATZDo6hceZYiwzBS6eSXUfjYh'),
'registration_ids' => array('d1WrqmdONL0:APA91bFRlokdsFFOXygqnRaSuWwD7QnJIhFGoZj1wPGuWzSxFxkaEca4FPDsPxpDp1FmpZSQ6lCoTsepH2PP9KbJ7HbEGQBhT0ofx8gMbr9P-JPL8eZlff4rkY7uS3CWXAzmg0KkbChK'),
'data' => $msg,
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
#Send Reponse To FireBase Server
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
echo $result;
curl_close( $ch );
and my ionic code is
pushObject.on('notification').subscribe((notification: any) => {
let json = JSON.parse(JSON.stringify(notification.additionalData));
console.log(json);
this.storage.set('notifs',json);
console.log( this.storage.get('notifs'));
if (notification.additionalData.foreground) {
console.log('i got fired foreground');
let youralert = this.alertCtrl.create({
title: 'Nouvelle audience',
message: notification.message,
buttons: [
{
text: "تخطي التنبيه",
},
{
text: "التفاصيل",
handler: () => {
this.nav.push(CasedetailPage,{id:json.case_id,titre:json.case_title,numero:json.case_number});
}
}]
});
youralert.present();
}
else if(notification.additionalData.background) {
this.nav.push(CasedetailPage,{id:json.case_id,titre:json.case_title,numero:json.case_number});
console.log('back');
}
});
right now of the app is running and forground the
if (notification.additionalData.foreground)
is excuted
and if the app is on background or is closed clicking on the notification only open the app.

Setting mail template in ses client

I am developing a web application using cakephp 3.0 and I have an email sending function earlier I was use php mail function. Now I am using AWS ses client. So in that ses client how I can render a template. In cake php email function it was possible. But I don't know how to do it in aws ses client.
My code is
public function testMail() {
if ($this->request->is('post')) {
$client = SesClient::factory(Configure::read('AWScredentials'));
$formData = $this->request->data;
$body = $formData['body'];
$ToAddresses = $formData['ToAddresses'];
$request = array();
$request['Source'] = 's#gmail.com';
$request['Destination']['ToAddresses'] = array($ToAddresses);
$request['Destination']['CcAddresses'] = 'ss#gmail.com';
$request['Message']['Subject']['Data'] = 'Test mail from vcollect ses';
$request['Message']['Subject']['Charset'] = 'ISO-2022-JP';
$request['Message']['Body']['Text']['Data'] = $body;
$request['Message']['Body']['Text']['Charset'] = 'ISO-2022-JP';
try {
$result = $client->sendEmail($request);
$messageId = $result->get('MessageId');
$this->log("Email sent! Message ID: $messageId", "info");
} catch (Exception $e) {
$this->log("The email was not sent. Error message:" . $e->getMessage(), "error");
}
} }
You must create a debug sender in app.php, just add it to your EmailTransport array like this, it's allow you to do a fake email without send it
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
'tls' => null,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
'debug' => [
'className' => 'Debug',
],
],
after to generate the email with your your template you can use this function for exemple
public function setTemplate($template,$layout = null,$viewVars = array(),$debug = 0)
{
if(empty($layout)) $layout = 'default';
$Email = new Email();
$Email->template($template, $layout)
->transport('debug') //<---- Allows you to simulate the message without sending it
->to(array('foo#bar.org'=>'toto'))
->emailFormat('html');
->viewVars($viewVars);
$Email->send();
/* Once email is generate, personally i duplicate the object for access to the protected proprety ( it's not very clean but i don't have a greatest solution)
The idea is to get _htmlMessage in the object */
$refObj = new ReflectionObject($Email);
$refProp1 = $refObj->getProperty('_htmlMessage');
$refProp1->setAccessible(TRUE);
if($debug == 1)
{
die(debug($refProp1->getValue($Email)));
}
return $refProp1->getValue($Email); // <---- your html code
}

Get customer Email in return URL after making payment using PayPal button

How can i get customer Email in return URL after making payment using PayPal button?
Thanks.
<?php
if(isset($_GET['tx']))
{
$tx = $_GET['tx'];
$your_pdt_identity_token = //token
$request = curl_init();
// Set request options
curl_setopt_array($request, array
(
CURLOPT_URL => 'https://www.sandbox.paypal.com/cgi-bin/webscr', //sandbox!!!
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => http_build_query(array
(
'cmd' => '_notify-synch',
'tx' => $tx,
'at' => $your_pdt_identity_token,
)),
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HEADER => FALSE,
// CURLOPT_SSL_VERIFYPEER => TRUE,
// CURLOPT_CAINFO => 'cacert.pem',
));
// Execute request and get response and status code
$response = curl_exec($request);
$status = curl_getinfo($request, CURLINFO_HTTP_CODE);
// Close connection
curl_close($request);
}
if($status == 200 AND strpos($response, 'SUCCESS') === 0)
{
$singlequantity = explode("\n",$response);
$email = $singlequantity[15];
$count = null;
$email = preg_replace('"%40"', '#', $email, -1, $count);
preg_match("/payer_email=(.*)/", $email, $email);
}
else
{
echo '<script type="text/javascript">
window.location="cancel.php";
</script>';
}
?>
i know i shoved it in real hard right now , but this might be useful to other users attempting to do this.

How to create sub category on Magento APi

I am currently using Magento ver. 1.5.0.1. Can anyone tell me how do i create a sub category using soapv2.
Here my code format
category_data = { "name" => "LIGHTING", "is_active" => 1 }
soap.call('catalogCategoryCreate',session,4,category_data,1, "include_in_menu")
I got some errors when i run this code.
: Attribute "include_in_menu" is required. (SOAP::FaultError)
Is that any solution for this problem.
Thanks.
category_data = { "name" => "LIGHTING", "is_active" => 1, "include_in_menu" => 1 }
This is how you can create category using SOAP V2
<?php
$host = "192.168.0.10/~aliasgar/magentoext/index.php"; //our online shop url
$client = new SoapClient("http://".$host."/api/v2_soap/?wsdl"); //soap handle
$apiuser= "aliasgar"; //webservice user login
$apikey = "aliasgar"; //webservice user pass
try {
$sess_id= $client->login($apiuser, $apikey); //we do login
$result = $client->catalogCategoryCreate($sess_id, 3, array(
'name' => 'Test Category',
'is_active' => 1,
'available_sort_by' => array('position'),
'default_sort_by' => 'position',
'include_in_menu' => '1',
));
var_dump ($result);
}
catch (Exception $e) { //while an error has occured
echo "==> Error: ".$e->getMessage(); //we print this
exit();
}
?>
Here 3 in the catalogCategoryCreate function is the parent category id.