Nexmo Messaging API - laravel-5

I am working on an sms feature by the Nexmo package. i however ran into a difficulty that i cant solve.
I have the following code in my rooutes php
Route::get('/sms/send/{to}', function(\Nexmo\Client $nexmo, $to){
$message = $nexmo->message()->send([
'to' => '0725959830',
'from' => '0791179389',
'text' => 'Sending SMS from Laravel. Woohoo!'
]);
Log::info('sent message: ' . $message['message-id']);
});
Then with this i get an error:
Target [Nexmo\Client\Credentials\CredentialsInterface] is not instantiable while building [Nexmo\Client].
Any ideas please

Related

I got Unable to resolve PSR request error with GuzzleHttp request

Implementing in my Laravel 7.6 app(pt hosts at http://local-votes.com of my local OS) api for
external api I want to make a test request from my other
Laravel 6.17.1 app and reading here : https://laravel.com/docs/7.x/passport
Converting Authorization Codes To Access Tokens
I try to use this example:
$http = new \GuzzleHttp\Client;
$client_id= 3; // client ID I made in my host app
$client_secret= 'XXX'; // client secret I made in my host app
$host= 'http://local-votes.com';
$response = $http->post($host.'/oauth/token', [
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => $client_id,
'client_secret' => $client_secret,
'redirect_uri' => $host.'/votes',
'code' => 'code',
// 'code' => $request->code,
],
]);
But I got error :
Illuminate\Contracts\Container\BindingResolutionException: Unable to resolve PSR request. Please i (truncated...)
{"userId":5,"exception":"[object] (GuzzleHttp\\Exception\\ServerException(code: 500): Server error: `POST http://local-votes.com/oauth/token` resulted in a `500 Internal Server Error` response:
Also I am not sure which values have I provide for fields 'client_secret' and 'code' ?
Can it be the issue ?
How to fix this error ?
Thanks!
Installing package nyholm/psr7
on provider app salved the problem!

Laravel 5.5 - Mailgun catch email errors

I am sending email via Mailgun from a Laravel 5.5 app like this...
Mail::send('emails.sendmessage', $data, function($message) use ($data) {
$message->to($data['email']);
$message->from('me#example.com.com', 'Ueer');
$message->subject('Sample Email');
});
/* Return Success Response */
return Response::json(array(
'error' => false,
'status_code' => 200,
'response' => 'success',
));
How can I catch Mailgun errors with this code? Sometimes MailGun returns an error message and I would like to return a different response if this happens
You can take a look at this question : Laravel 5 - How Do You Catch an Mail::send() Error?
Adding a try and catch should do the trick.
If you don't want to add a try/catch for whatever reason, I would recommend you to validate beforehand every parameters susceptile of throwing an error from Mail::send

Payments with Laravel Omnipay (mollie gateway)

I'm currently stuck trying to create a payment with Omnipay. I have the following libraries installed in my project:
https://github.com/barryvdh/laravel-omnipay
https://github.com/thephpleague/omnipay-mollie
But I'm having problems starting. I see in the example that I need these params:
$params = [
'amount' => $order->amount,
'issuer' => $issuerId,
'description' => $order->description,
'returnUrl' => URL::action('PurchaseController#return', [$order->id]),
];
But what's the $issuerId? I would like to have an integration with Mollie.
Does someone maybe has an example of using laravel Omnipay with Mollie?
UPDATE:
I'm trying to submit my form with an ajax call. In my PHP function I have the following code:
$gateway = Omnipay\Omnipay::create('Mollie');
$gateway->setApiKey('test_gSDS4xNA96AfNmmdwB3fAA47zS84KN');
$params = [
'amount' => $ticket_order['order_total'] + $ticket_order['organiser_booking_fee'],
'description' => 'Kapelhoek wijkfeesten',
'returnUrl' => URL::action('EventCheckoutController#fallback'),
];
$response = $gateway->purchase($params)->send();
if ($response->isSuccessful()) {
// payment was successful: update database
print_r($response); die;
} elseif ($response->isRedirect()) {
// redirect to offsite payment gateway
return $response->getRedirectResponse(); die;
} else {
// payment failed: display message to customer
echo $response->getMessage(); die;
}
But now I'm getting the following console error:
XMLHttpRequest cannot load https://www.mollie.com/payscreen/select-method/PRMtm6qnWG. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://kapelhoektickets.dev' is therefore not allowed access.
How can I fix this?
But what's the $issuerId?
Issuer ID is The issuer's unique identifier, for example ideal_ABNANL2A. When creating a payment, specify this ID as the issuer parameter to forward the consumer to their banking environment directly.
You can see a list of available issuers by calling this API url:
https://api.mollie.nl/v1/issuers
as stated in https://www.mollie.com/be/docs/reference/issuers/list
To read more about the issuer visit this part of the API-documentation:
https://www.mollie.com/be/docs/reference/issuers/get

laravel5.2 Mailgun work but not send the email

Hello I setup mailgun correctly. and did form contact us.
To send the message to my email by this code
public function send_contact_us()
{
$data = array(
'name' => Request::get('name'),'email'=>Request::get('email'),'subject'=> Request::get('subject'));
$client_m=Request::get('message');
$data_message=array('message_c'=>$client_m);
echo "we above MAIL";
Mail::send('emails.message',$data_message, function ($message)use ($data) {
$message->from($data['email'], 'E-SHOPPER');
$message->to("azharnabil013#yahoo.com")->subject($data['subject']);
});
return view('contact_us', array('title' => 'Welcome', 'description' => '', 'page' => 'contact_us','subscribe'=>'','sent'=>"Message has been sent successfuly"));
}
The code run correctly and this page display
But when I check my email I didn't find any message
I don't know why this problem .please, anyone help me.

Sending Email in Laravel Using Swift Mailer without Gmail

Hello i'm new to laravel and still getting familiar with certain features, i would like to know how i can send an email from my laravel application without using gmail smtp settings. Like the way the mail function works in basic PHP. Is this possible? I have tried googling it but i have been unable to find a solution, they all use gmail.
Go to your app/config/mail.php
change driver, host and from
'driver' => 'mail',
'host' => '',
'from' => array('address' => 'us#example.com', 'name' => 'Laravel'),
or you can set 'from' within
Mail::send('emails.welcome', $data, function($message)
{
$message->from('us#example.com', 'Laravel');
$message->to('foo#example.com')->cc('bar#example.com');
});

Resources