Programmatically send SMS to customers when a order delivery status is changed - magento

I want to send a notification SMS to customers when I change order delivery status from admin panel, purchased SMS service from India

You need to check the order status for changing - there is no event for this so you need:
Event: sales_order_load_after to get the order status after load
Method:
public function fetchOrderStatus(Varien_Event_Observer $observer){
try{
if (!Mage::registry('cartware_order_status')){
Mage::register('cartware_order_status', $observer->getOrder()->getStatus());
}
}
catch (Exception $e){
Mage::logException("UNEXPECTED PROBLEM WIH REGISTER");
Mage::logException($e);
}
return;
}
Event: sales_order_save_after to get the order status after save:
Method:
public function checkOrderStatus(Varien_Event_Observer $observer){
try{
if(!Mage::registry('cartware_order_status')){
return;
}else{
$orderStatus = Mage::registry('cartware_order_status');
}
}
catch (Exception $e){
Mage::logException("UNEXPECTED PROBLEM WIH REGISTRY");
Mage::logException($e);
}
if ($orderStatus != $observer->getOrder()->getStatus() &&
$observer->getOrder()->getStatus() == [STATUS YOU WANT TO REACT IF CHANGE TO]){
sendYourSmsMethod();
}
}
Good luck!

Related

How To Check If Notification Is Sent Successfully In Laravel

I am unable to find in the documentation of how to handle the notification (what to do if notification is sent successfully or not)
NotificationController
public function AskForLevelUp()
{
$admin = User::where('is_admin', 1)->first();
$sendNotification = Notification::send($admin, new LevelUpNotification(Auth::user()->id));
if ($sendNotification->success()) // **HOW TO DO THIS CORRECTLY**
{
return back()->with('success', 'Your request has been submitted, please wait for admin confirmation.');
}
else
{
return back()->with('failure', 'Something went wrong, your request is not submitted. Please try again later.');
}
}
I've also read that send() has void return value here. Does anyone know how to handle this?

Xamarin InAppBilling showing ItemUnavailable for purchase on Android

I'm implementing the InAppBilling plugin in my Xamarin Forms 5 app for auto-renewing subscriptions.
I have the "subscriptions" set up on Google Play and they're active. When I ask for a list of subscription items, I get the list fine but when I try make a purchase, I get the following error that indicates the item is not available.
I'm running this on a real device connected to my laptop via USB. Any idea what I'm doing wrong?
Here's my purchase subscription method which is directly from documentation here:
public async Task<bool> Subscribe(string productId)
{
var billing = CrossInAppBilling.Current;
try
{
var connected = await billing.ConnectAsync();
if (!connected)
return false;
//check purchases
var purchase = await billing.PurchaseAsync(productId, ItemType.Subscription);
//possibility that a null came through.
if (purchase == null)
{
//did not purchase
return false;
}
else
{
//purchased!
if (Device.RuntimePlatform == Device.Android)
{
// Must call AcknowledgePurchaseAsync else the purchase will be refunded
//await billing.AcknowledgePurchaseAsync(purchase.PurchaseToken);
}
return true;
}
}
catch (InAppBillingPurchaseException purchaseEx)
{
//Billing Exception handle this based on the type
throw new Exception("Error: " + purchaseEx);
}
catch (Exception ex)
{
//Something else has gone wrong, log it
throw new Exception();
}
finally
{
await billing.DisconnectAsync();
}
}
As I mentioned before, I see the subscription items available and active on Google Play. I also made sure, I'm getting them from "Subscriptions" and NOT "In-App Products". I'm using the ID that I copy and paste from the "Product ID" column on Google Play Console -- see below:
Any idea what the issue here may be?

Get websocket data in laravel controller

I have an external WebSocket link where im getting data. My requirement is to receive those data in laravel controller and handle them.
How to listen in controller.
Finally i found the solution.
this has helped me.
$clientWebSoket = new \WebSocket\Client(
'wss://somelink'
);
$clientWebSoket->send(
'{"method":"test","symbols":"some data"}'
);
while ($i) {
try {
$message = $clientWebSoket->receive();
dump($message);
} catch (\WebSocket\ConnectionException $e) {
dd($e);
}
}
$clientWebSoket->close();

magento newsletter keeps returning an error even after email is saved

There was a problem with the subscription.
this is the message I get after I enter an email. When I go to the admin panel the email is added.
I would like it NOT to display this message. any suggestions please
The only place in Magento that error string occurs is in the following try/catch block
#File: app/code/core/Mage/Newsletter/controllers/SubscriberController.php
try {
//...snip!...
}
catch (Mage_Core_Exception $e) {
$session->addException($e, $this->__('There was a problem with the subscription: %s', $e->getMessage()));
}
catch (Exception $e) {
$session->addException($e, $this->__('There was a problem with the subscription.'));
}
Since you reported the error message as "There was a problem with the subscription.", that means the newsletter subscription code is throwing some sore of PHP exception, caught by the catch (Exception $e) { block. Magento does not output the messages from PHP exceptions. If I was in your position I'd temporarily change the exception handling code to include the error message
$session->addException($e, $this->__('There was a problem with the subscription. ' . $e->getMessage()));
This will let you track down the PHP error that's triggering your error message.
Per the comment below, the only place the "Cannot set standard header from addHeader()" exception error exists is
#File: lib/Zend/Mail.php
$prohibit = array('to', 'cc', 'bcc', 'from', 'subject',
'reply-to', 'return-path',
'date', 'message-id',
);
if (in_array(strtolower($name), $prohibit)) {
/**
* #see Zend_Mail_Exception
*/
#require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('Cannot set standard header from addHeader()');
}
$value = $this->_filterOther($value);
$value = $this->_encodeHeader($value);
$this->_storeHeader($name, $value, $append);
return $this;
My guess is somewhere in your system someone's added some custom code that tries to set one of the standard email headers via the addHeader method.

OAuthException not catched with C# FacebookSDK

I try to get my code working with catching certain errors. I store the token for a user after he or she grants permission to my app (this is a WP7 app). When I try to post on the wall by using the stored token it works. When I remove the permissions on facebook it throws an OAuthException. I can't catch it it seems. My app just crashes. This is the code I used:
private object PostToFacebook()
{
_fbApp = new FacebookClient(_appsettings.faceBookToken);
FacebookAsyncCallback callback = new FacebookAsyncCallback(this.postResult);
var parameters = new Dictionary<string, object>();
parameters.Add("message", "message on wall");
try
{
_fbApp.PostAsync("me/feed", parameters, callback);
}
catch (Exception ex)
{
}
return null;
}
private void postResult(FacebookAsyncResult asyncResult)
{
if (asyncResult.Error == null)
{
status = "succes";
}
else
{
status = "error" + asyncResult.Error.Message;
}
}
The try catch doesn't catch anything and the generic exception handler in my app.xaml.cs either.
Any ideas how to catch this error so I can ask the user to authenticate again?
Put your try..catch in the callback.
You can also catch exceptions globally by handling the UnhandledException event on the App object.

Resources