Closed EricKarijo closed 3 years ago
I want to working example of how to refresh the accesstoken. This is my code to connect to Mollie:
// Connect to Mollie public function connect() { return Socialite::with('mollie') ->scopes(['profiles.read','profiles.write','payments.read','payments.write']) // Additional permission: profiles.read ->redirect(); }
My login callback is: public function login_callback() {
if ( isset( $_GET['error'] )) { $error = $_GET['error']; $err_desc = $_GET['error_description']; if ( $error && $err_desc ) { return redirect()->route('finances.owner')->with( 'error', $error . ': ' . $err_desc ); } } try { // get current mollie account $mollie_user = Socialite::with('mollie')->user(); // current restorant owner $current_user = auth()->user(); $code = $_GET['code']; // auth code $state = $_GET['state']; // state $token = $mollie_user->token; // access token $refreshToken = $mollie_user->refreshToken; // not always provided $expiresIn = $mollie_user->expiresIn; ... storing above variables in db } catch { }
This is working fine.
After this when a customer want to make a payment I want to refresh the accesstoken.
This is how payment is created:
public function createPayment( Order $order) {
// REFRESH ACCESSTOKEN IF NEEDED How to this part ?? $token = $restorant->user->mollie_authToken; Mollie::api()->setAccessToken( $token); $ord_total = sprintf("%.2f", floatval($order->delivery_price + $order->order_price + $order->static_fee )); $applicationFee = [ "amount" => [ "currency" => "EUR", "value" => (string)sprintf("%.2f", floatval($restorant->static_fee )), // You must send the correct number of decimals, thus we enforce the use of strings ], "description" => "Platform fee bestelling #" . $order->id . " bij restaurant '" . $restorant->name . "'", ]; $payment = Mollie::api()->payments->create([ "amount" => [ "currency" => "EUR", "value" => $ord_total, // You must send the correct number of decimals, thus we enforce the use of strings ], "description" => "Bestelling #" . $order->id . " bij restaurant '" . $restorant->name . "'", "redirectUrl" => 'https://' . $host . '/mollie/webhooks/mollie/redirected/', // route('mollie.webhooks.redirect'), // route('orders.inde//x'), "webhookUrl" => route('mollie.webhooks.normal'), // route('webhooks.mollie'), "metadata" => [ "order_id" => $order->id, "profile" => $restorant->user->mollie_profileId, ], // "applicationFee" => $applicationFee, "profileId" => $restorant->user->mollie_profileId, ]);
}
Before creating the payment I want to refresh the accesstoken see // REFRESH ACCESSTOKEN IF NEEDED in the code
How to do that ?
use Laravel\Socialite\Facades\Socialite; $accessToken = Socialite::with('mollie')->getRefreshTokenResponse($refreshToken);
Specifications
Describe the issue
I want to working example of how to refresh the accesstoken. This is my code to connect to Mollie:
// Connect to Mollie public function connect() { return Socialite::with('mollie') ->scopes(['profiles.read','profiles.write','payments.read','payments.write']) // Additional permission: profiles.read ->redirect(); }
My login callback is: public function login_callback() {
This is working fine.
After this when a customer want to make a payment I want to refresh the accesstoken.
This is how payment is created:
public function createPayment( Order $order) {
}
Before creating the payment I want to refresh the accesstoken see // REFRESH ACCESSTOKEN IF NEEDED in the code
How to do that ?