@extends('OmniPayViews::layouts.redirection-layout')

@section('title')<title>Redirecting to Payfort, please be patient....</title>@endsection

@section('content')
<?php

    if(isset(session('login')->email)){ $email = session('login')->email; }else{ $email = "info@test.com"; }

    $urlAdd = "";
    if(isset(session('login')['token'])){
        $urlAdd = "&t=".session('login')['token'];
    }
    $response = (new \twa\omnipay\repositories\payfort(
        config('omnipay.'.$provider.'.data')['PAYFORT_MERCHANT_ID'],
        config('omnipay.'.$provider.'.data')['PAYFORT_ACCESS_CODE'],
        config('omnipay.'.$provider.'.data')['PAYFORT_SHA_REQUEST_PHRASE'],
        config('omnipay.'.$provider.'.data')['PAYFORT_SHA_REQUEST_PHRASE'],
        $amount,
        $currency,
        "New purchase at ".env('APP_NAME'),
        $email,
        '/omnipay/response/unknown?paid='.$id.$urlAdd.'&lang='.app()->getLocale(),
        true
        )
    )->processRequest('checkout');

    echo $response['form'];


?>
<div class="text">Redirecting, please be patient</div>
<script language="javascript">
    $('#payfort_payment_form').submit();
    $('#submit').click();

    {{--function setCookie(cname, cvalue, exdays) {--}}
    {{--    const d = new Date();--}}
    {{--    d.setTime(d.getTime() + (exdays*24*60*60*1000));--}}
    {{--    let expires = "expires="+ d.toUTCString();--}}
    {{--    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";--}}
    {{--}--}}
    {{--setCookie('onlineToken','{{ session('login')['token'] }}',30);--}}
</script>
@endsection
