PHP code example of chargily / epay-symfony

1. Go to this page and download the library: Download chargily/epay-symfony 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/ */

    

chargily / epay-symfony example snippets

bash
    /**
     * @Route("/chargily/webhook/{OrderNumber}",name="chargily_webhook")
     * @throws \Exception
     */
    public function chargilyWebhook(Request $request)
    {
        //getting your order number
        $number = $request->attributes->get('OrderNumber');

        //part or code for searching your order by number
        /*
         *
         */

        //getting request content
        $data = json_decode($request->getContent(), true);
        $headers = json_decode($request->headers, true);

        $hashedData =  hash_hmac('sha256', json_encode($data) , $this->getParameter('secret_key'));

        if (isset($data) and isset($number)) {
            if($data['invoice']['status'] == 'paid'){

                //part where you update your order status for paid status

                return new JsonResponse([
                    'code' => 200,
                    'message' => 'Update status with success'
                ]);
            }elseif($data['invoice']['status'] == 'failed'){
                //part where you update your order status for failed status

                return new JsonResponse([
                    'code' => 200,
                    'message' => 'Update status with success'
                ]);
            }
            elseif( $data['invoice']['status'] == 'canceled'){
                //part where you update your order status for canceled status
                return new JsonResponse([
                    'code' => 200,
                    'message' => 'Update status with success'
                ]);
            }
        } else {
            return new JsonResponse([
                'code' => 400,
                'message' => 'Update status Failed'
            ]);
        }

    }