PHP code example of albakov / laravelcloudpayments

1. Go to this page and download the library: Download albakov/laravelcloudpayments library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

albakov / laravelcloudpayments example snippets


php artisan vendor:publish --provider='Albakov\LaravelCloudPayments\ServiceProvider' --tag=config



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Order;

class MyNotifier {
~ ~ ~

    // Use trait
    use \Albakov\LaravelCloudPayments\Notifications;

    /**
     * Check payment
     * https://cloudpayments.ru/Docs/Notifications#check
     * @param Illuminate\Http\Request $request
     * @return json
     */
    public function check(Request $request)
    {
        $data = $this->validateAll(Request $request);
        return response()->json($data);
    }
    
    /**
     * Confirm payment
     * https://cloudpayments.ru/Docs/Notifications#pay
     * @param Illuminate\Http\Request $request
     * @return json
     */
    public function pay(Request $request)
    {
        $data = $this->validateAll(Request$request);
         
        if ((int) $data['code'] === 0) {
            // payment success
            // mark order payment status - success
            // send email to admin and customer
            // etc ...
        }
        
        return response()->json($data);
    }
    
    /**
     * Check Secret, orderId, Amount
     * @param Illuminate\Http\Request $request
     * @return json
     */
    public function validateAll($request)
    {
        // Check secrets
        $result = $this->validateSecrets($request);

        if ($result['code'] !== 0) {
            return $result;
        }
        
        // Get order
        $order = Order::find($request->InvoiceId);
        
        // Check orders
        $result = $this->validateOrder($request->InvoiceId, $order->id);

        if ($result['code'] !== 0) {
            return $result;
        }
        
        // Check amounts
        $result = $this->validateAmount($request->Amount, $order->amount);

        if ($result['code'] !== 0) {
            return $result;
        }

        return ['code' => 0]; // Success
    }

~ ~ ~

}



~ ~ ~

Route::group(['prefix' => 'cloudpayments'], function() {
    Route::match(['GET', 'POST'], 'check', 'MyNotifier@check');
    Route::match(['GET', 'POST'], 'pay', 'MyNotifier@pay');
});

~ ~ ~

protected $except = [
    // ...
    'cloudpayments/*'
];