|
1 | | -# epay-gateway-symfony |
2 | | -Chargily ePay Gateway (Symfony Package) |
| 1 | +# chargily-epay-symfony |
| 2 | +Symfony Plugin for Chargily ePay Gateway |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +# Installation |
| 7 | +1. Via Composer (Recomended) |
| 8 | +```bash |
| 9 | +composer require chargily/epay-symfony |
| 10 | +``` |
| 11 | + |
| 12 | +2. Register the bundle, add this line at the end of the file config/bundles.php |
| 13 | +```bash |
| 14 | +\Chargily\SymfonyBundle\ChargilySymfonyBundle::class => ['all' => true], |
| 15 | +``` |
| 16 | + |
| 17 | +3. Import the services, Add the follow line in config/services.yml |
| 18 | +```bash |
| 19 | +imports: |
| 20 | + - { resource: "@ChargilySymfonyBundle/config/services.yaml" } |
| 21 | +``` |
| 22 | +
|
| 23 | +4. Configure the api keys Add the follow line in config/services.yml |
| 24 | +```bash |
| 25 | +parameters: |
| 26 | + api_key: "API_KEY" |
| 27 | + secret_key: "SECRET_KEY" |
| 28 | +``` |
| 29 | +
|
| 30 | +5. Process payment and redirection to payment page |
| 31 | +
|
| 32 | +```bash |
| 33 | + $payload = array( |
| 34 | + "client" => "test", |
| 35 | + 'client_email' => "test@gmail.com", |
| 36 | + "invoice_number" => '123456789', |
| 37 | + "amount" => 110, |
| 38 | + 'discount' => 0, |
| 39 | + 'mode' => 'CIB', |
| 40 | + 'back_url' => "https://test.com", |
| 41 | + 'webhook_url' => "https://test.com" . "/" . "webHookSuffixRoute". "/" ."OrderNumber", |
| 42 | + //back_url example when you want to take your host base url |
| 43 | + //'back_url' => $request->getSchemeAndHttpHost(), |
| 44 | + //webhook_url example when you want to take your host base url and add your suffix route for the webhook |
| 45 | + //'webhook_url' => $request->getSchemeAndHttpHost() . "/" . you_back_url_suffix_here . "/" .Order_Number, |
| 46 | + 'comment' => 'My Payment Comment.', |
| 47 | + 'api_key' => $this->getParameter('api_key'), |
| 48 | + ); |
| 49 | + |
| 50 | + $chargyliController = new ChargilyEpaySymfonyController(); |
| 51 | + |
| 52 | + $response = $chargyliController->pay($payload); |
| 53 | + $status_code = $response->getStatusCode(); |
| 54 | + $response = json_decode($response->getContent()); |
| 55 | + if ($status_code == 200) { |
| 56 | + //redirect to chargily payment gateway |
| 57 | + return $this->redirect($response->response); |
| 58 | + } else { |
| 59 | + // This is a error message depending on issue that happen |
| 60 | + dd($status_code . " " . $response->response); |
| 61 | + } |
| 62 | + |
| 63 | +``` |
| 64 | +
|
| 65 | +6. success Message for the Process payment |
| 66 | +```bash |
| 67 | +200 => getting redirection link with success => Redirection to url |
| 68 | +``` |
| 69 | +
|
| 70 | +7. Error Message for the Process payment |
| 71 | +```bash |
| 72 | +400 => There mode must be CIB,EDAHABIA option Only |
| 73 | +400 => There amount must be numeric and greather or equal than 75 |
| 74 | +400 => There is issue \for connecting payment gateway. Sorry \for the inconvenience => with error message |
| 75 | +400 => There is missing information in payment parameters |
| 76 | +``` |
| 77 | +8. Webhook Template |
| 78 | +```bash |
| 79 | + /** |
| 80 | + * @Route("/chargily/webhook/{OrderNumber}",name="chargily_webhook") |
| 81 | + * @throws \Exception |
| 82 | + */ |
| 83 | + public function chargilyWebhook(Request $request) |
| 84 | + { |
| 85 | + //getting your order number |
| 86 | + $number = $request->attributes->get('OrderNumber'); |
| 87 | + |
| 88 | + //part or code for searching your order by number |
| 89 | + /* |
| 90 | + * |
| 91 | + */ |
| 92 | + |
| 93 | + //getting request content |
| 94 | + $data = json_decode($request->getContent(), true); |
| 95 | + $headers = json_decode($request->headers, true); |
| 96 | + |
| 97 | + $hashedData = hash_hmac('sha256', json_encode($data) , $this->getParameter('secret_key')); |
| 98 | + |
| 99 | + if (isset($data) and isset($number)) { |
| 100 | + if($data['invoice']['status'] == 'paid'){ |
| 101 | + |
| 102 | + //part where you update your order status for paid status |
| 103 | + |
| 104 | + return new JsonResponse([ |
| 105 | + 'code' => 200, |
| 106 | + 'message' => 'Update status with success' |
| 107 | + ]); |
| 108 | + }elseif($data['invoice']['status'] == 'failed'){ |
| 109 | + //part where you update your order status for failed status |
| 110 | + |
| 111 | + return new JsonResponse([ |
| 112 | + 'code' => 200, |
| 113 | + 'message' => 'Update status with success' |
| 114 | + ]); |
| 115 | + } |
| 116 | + elseif( $data['invoice']['status'] == 'canceled'){ |
| 117 | + //part where you update your order status for canceled status |
| 118 | + return new JsonResponse([ |
| 119 | + 'code' => 200, |
| 120 | + 'message' => 'Update status with success' |
| 121 | + ]); |
| 122 | + } |
| 123 | + } else { |
| 124 | + return new JsonResponse([ |
| 125 | + 'code' => 400, |
| 126 | + 'message' => 'Update status Failed' |
| 127 | + ]); |
| 128 | + } |
| 129 | + |
| 130 | + } |
| 131 | +``` |
| 132 | +9. Clear the Cache And Enjoy |
| 133 | +```bash |
| 134 | +php bin/console cache:clear |
| 135 | +``` |
| 136 | +
|
| 137 | +This Plugin is to integrate ePayment gateway with Chargily easily. |
| 138 | +- Currently support payment by **CIB / EDAHABIA** cards and soon by **Visa / Mastercard** |
| 139 | +- This repo is recently created for **Sylius Plugin**, If you are a developer and want to collaborate to the development of this plugin, you are welcomed! |
| 140 | +
|
| 141 | +# Contribution tips |
| 142 | +1. Make a fork of this repo. |
| 143 | +2. Take a tour to our [API documentation here](https://dev.chargily.com/docs/#/epay_integration_via_api) |
| 144 | +3. Get your API Key/Secret from [ePay by Chargily](https://epay.chargily.com.dz) dashboard for free. |
| 145 | +4. Start developing. |
| 146 | +5. Finished? Push and merge. |
0 commit comments