I am integrating Orange Money Payment gateway with my Yii2 basic Application to be able to receive local payments on this application.
In this API, when the user initiates a transaction, I receive some data after sending a curl request to the Orange money API. I store this data in my Database with a key call notif_token. The user is then redirected to orange payment portal where the payment is done. when the User completes a payment process on their portal, they send me json response to a particular url call Notifcation URL. I am suppose to receive this data, update my Database and grant access to this user to some resources.
Everything works well till the level of receiving the feedback in from them through the notification URL.
I have tried all I know to receive this information but to no avail since this action is not an api url. I have written my action as shown below but I do not know what I am missing.( might be a configuration for this action or something).
public function actionOnotification(){
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$request = \yii::$app->request->post();
$transaction =OrangeFeedback::findOne(['notif_token'=>$request['notif_token']]);
$transaction->status = $request['status'];
$transaction->txnid = $request['txnid'];
$transaction->save();
//do some processing here
}
I do not know how to solve this problem as I feel I am missing a fundamental concept here( might be on how to configure a Yii2 basic application action to receive json data, might be how to convert that action into an API call URL or something which I can not yet figure out). Any help on this will be greatly appreciated as I can't find any resources online to help me.
To receive JSON data you need to configure your request component in the config:
'components' => [
...
'request' => [
'parsers' => [
'application/json' => 'yii\web\JsonParser',
]
],
...
]
See the docs for more information
Related
I need help with Laravel Cashier.
I'm using laravel cashier on backend and vue on client side.
On client I setup stripe object, elements and card.
In the meanwhile I request to serve a client_secret making a PaymentIntent
$payment_intent = PaymentIntent::create(
['amount' => $request["price"],
'currency' => "eur",
'payment_method_types' => ['card'],
'customer' => $stripe_customer->id,
], [
'api_key' => config('services.stripe.secret'),
]);
When user input credit card data and confirm using the client_secret
I call this function in client side
this.stripe.confirmCardPayment(this.stripe_payment_intent.client_secret, {
payment_method: {
card: this.stripe_card,
billing_details: {
name: 'Test Name'
}
},
setup_future_usage: 'off_session'
})
...
On then I call the server passing the result.
On the server side
$stripeCharge = $request->user()->charge(
$request["paymentIntent"]["amount"], $request["paymentIntent"]["payment_method"]
);
It works fine, withouth sca (3d secure)
But when the test card require 3d secure (4000002500003155 or 4000002760003184) on the client all goes fine, displaying the 3d secure
dialog, the confirmCardPayment succeed, but in last step when calling charge I got
The payment attempt failed because additional action is required before it can be completed.
Why? All the actions is performed on the client side.. why the server not agree?
p.s. I need only single charge without store any payment method
The problem was that confirmCardPayment already charge the user.
So calling again in the server side make the error because double charge on 3d secure card is not possible.
I had to remove charge on the server side and using PaymentIntent::retrieve in order to verify the status and check if already processed in my business logic.
I have an application on Yii2.
I have an external vendor i want to redirect. For example, i am encrypting the current user info, and want to send that to the external vendor, so the user information is automatically populated on his website.
Everything works fine if i do that on the front end side using JS.
The problem i have is only my app server is whitelisted to the vendor. So i need to make the redirection happen on the backend.
I tried several method, and even with Guzzle HTTP, and it doesn't redirect.
TO be clear, i am not looking for a simple redirect, it is a form post on external URL.
I went though this post, but the problem remain the same...
Yii2 how to send form request to external url
Does anybody faced this issue?
If I understand you correctly, you want to POST data received from your frontend to the server of a third party company (let's call them ACME). Your webserver is whitelisted by ACME but your clients are not (which is good). You want to show a page on your server and not a page on the ACME server after the POST, right?
You have to send the data with a separate request from your server to the ACME server. You cannot create a HTML <form> and put the ACME server in the action parameter of it, because the request would be sent from the client and not your backend, failing at the whitelist. After you validate your client input, you can send it with guzzle to ACME.
With the status code you can decide if your request was successful or not. You can read more about guzzle here
The code sample below shows how you could POST the $payload (a fictional blog post if you will) as JSON to the ACME server and output a line with the request result.
$payload = [
'username' => 'john.doe',
'postContent' => 'Hello world',
];
$client = new GuzzleHttp\Client();
$response = $client->post('https://acme.example.org/endpoint',['http_errors' => false, 'json' => $payload]);
if($response->getStatusCode() === 200){
echo "Request OK";
}else{
echo "Request failed with status ".$response->getStatusCode();
}
I'm unclear after reading through Slack's documentation around Incoming Webhooks. It seems like there's some ambiguity around Incoming Webhooks vs. posts through their chat API. It sounds like if I call it from https://my-application.yxz/api/notify?key=123123123123, and post to Slack from there, then Slack's action buttons will reply to that same URL, but I can't confirm that.
https://api.slack.com/docs/message-attachments
I'm successfully sending messages to the specified channel, but I can't figure out how to get a response back, or how to change the URL the actions will send their own payload to. Is that even possible?
For context of the code below, I'm using Laravel. Ideally, I wanted to only retain a Slack Webhook URL in the user settings for their store's location so they could receive Slack notifications triggered by our API being hit.
This is the payload I'm sending to the webhook and it works fine, however I would like to add actionable buttons and post the payload back to my external site. I'm not sure if Incoming Webhooks are even the right approach. Can someone shed some light on this?
# $helpdesk => contains webhook URL and other details
# $prompt => just some text
# $prompt_id => id associated with prompt object passed into the function this is found in
# $device => the source of this prompt
$payload = json_encode([
"text" => "A customer at $device->name requires attention",
"username"=>"Our Alert Thing",
"icon_emoji"=>":wave:",
"attachments"=> [
[
"fallback"=> $prompt,
"author_name"=> "Customer # $device->name",
"title"=> $prompt,
"text"=> "Let them know if you can help",
"callback_id"=> "csprompt_".$prompt_id,
"color"=> "#24ACE2",
"actions"=> [
[
"name"=> "action",
"type"=> "button",
"text"=> "I call dibs",
"style"=> "primary",
"value"=> "helping",
],
]
]
]
]);
$res = $client->post($helpdesk->slack_webhook, ['body'=>$payload]);
You can not programmatically set your action URL. Slack will send all interactive message requests (e.g. from a user clicking on one of your buttons) to the "request URL" that you have configured for your Slack app.
Check this link for details on where to find the request URL.
I think technically you can use incoming webhooks, but I would recommend using the API with chat.postMessage, because incoming webhooks are very limited. e.g. they can only be used with one pre-configured channel.
This is not a duplication of my previous question here.
Am using botman to create a bot for my slack app.
Using the slack api, i have created a bot that i want to connect to botman on my laravel app. Am using ngrok to tunnel localhost. I have to get my url verified first in order to use it for the bot. Well i try to verify the url but i keep getting this error.
Your request URL didn’t respond with the correct challenge value. Update your URL to receive a new request and value.
Checking the ngrok terminal shows that the request from slack is being received and the status is 200. If i reproduce the request using postman, the value of the challenge parameter is returned, on slack i still get the erorr. I use this code to load the slack driver on my routes file.
<?php
use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\Drivers\Slack\SlackDriver;
use BotMan\BotMan\Drivers\DriverManager;
Route::match(['get', 'post'],'botman', function () {
DriverManager::loadDriver(SlackDriver::class);
// Create BotMan instance
$config = [
'slack' => [
'token' => '***slack Token***' //slack token
]
];
$botman = BotManFactory::create($config);
// give the bot something to listen for.
$botman->hears('hello', function (BotMan $bot) {
$bot->reply('Hello yourself.');
});
// start listening
$botman->listen();
});
I went a head to try force the response with the challenge parameter in the url like so on my routes file.
$payload = $request->json();
if ($payload->get('type') === 'url_verification') {
return $payload->get('challenge');
}
SlackBot::hears('keyword', function (Bot $bot) {
$bot->respond('lets begin');
});
This still does not work, i still get the URL didn’t respond with the correct challenge value... error.
What am i missing? or how should i use the slack driver to have it respond with the right parameters? The web driver works perfectly.
I noticed that the slack api expects the challenge value in json format.
simply doing return $payload->get('challenge'); . does not do the trick. I changed this to return response->json( return $payload->get('challenge'));. This got my url verified.
Am not sure whether this is an issue with the whole botman slack-driver , I didn't find anyone else with the same issue.
I am using laravel 5.5 and trying to do integrate a payment processor (local one) into the solution I am building. The issue : The processor is giving data needed on requests as data that needs to posted, and the problem is that some of that data are confidential !
So if I integrate them as hidden inputs in the form and post them using JS or even as a normal form, any user could access that data.
The solution for me is to handle the request of the user (his choice of paying online) and from there, I redirect him to the payment gateway with a POST method that contains all the data needed by the procesor.
What I've tried so far is using Guzzle, but guzzle is somehow acting like an ajax request, actualy even like an API request, it waits for data to return, while I don't need it, in fact, I have to redirect the user so that he can enter his payment details and authorize the payment.
$user = Auth::user();
$processorData = [
'NumSite' => 'XXXXXX',
'Password' => 'XXXXXXX',
'Amount' => $invoice->total,
'Devise' => 'TND',
'orderId' => $id,
'PayementType' => 1,
'EMAIL' => $user->email,
'signture' => sha1('XXXXXX'.'XXXXXXX'.$id.$invoice->total.'TND')
];
$client = new Client();
$request = $client->post('https://preprod.gpgcheckout.com/Paiement_test/Validation_paiement.php',
['paiment' => $processorData]);
I also tried a redirect, a curl .. same thing.
What I'm looking to achieve is like posting some data on behalf of user choice but without letting anyone see the hidden fields in my source code (html page)
Thank you