diff --git a/README.md b/README.md index e29901d..62a6ed6 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ return [ #KASHIER 'KASHIER_ACCOUNT_KEY' => env('KASHIER_ACCOUNT_KEY'), 'KASHIER_IFRAME_KEY' => env('KASHIER_IFRAME_KEY'), + 'KASHIER_TOKEN' => env('KASHIER_TOKEN'), 'KASHIER_URL' => env('KASHIER_URL', "https://checkout.kashier.io"), 'KASHIER_MODE' => env('KASHIER_MODE', "test"), //live or test 'KASHIER_CURRENCY'=>env('KASHIER_CURRENCY',"EGP"), @@ -163,6 +164,7 @@ $payment->verify($request); //outputs [ 'success'=>true,//or false + 'payment_id'=>"PID", 'message'=>"Done Successfully",//message for client 'process_data'=>""//payment response ] diff --git a/config/nafezly-payments.php b/config/nafezly-payments.php index 2b64dc6..59aae75 100644 --- a/config/nafezly-payments.php +++ b/config/nafezly-payments.php @@ -20,6 +20,7 @@ #KASHIER 'KASHIER_ACCOUNT_KEY' => env('KASHIER_ACCOUNT_KEY'), 'KASHIER_IFRAME_KEY' => env('KASHIER_IFRAME_KEY'), + 'KASHIER_TOKEN' => env('KASHIER_TOKEN'), 'KASHIER_URL' => env('KASHIER_URL', "https://checkout.kashier.io"), 'KASHIER_MODE' => env('KASHIER_MODE', "test"), //live or test 'KASHIER_CURRENCY'=>env('KASHIER_CURRENCY',"EGP"), diff --git a/src/Classes/KashierPayment.php b/src/Classes/KashierPayment.php index d9578cd..6f815e1 100644 --- a/src/Classes/KashierPayment.php +++ b/src/Classes/KashierPayment.php @@ -3,6 +3,7 @@ namespace Nafezly\Payments\Classes; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Http; use Nafezly\Payments\Interfaces\PaymentInterface; use Nafezly\Payments\Classes\BaseController; @@ -12,6 +13,7 @@ class KashierPayment extends BaseController implements PaymentInterface public $kashier_mode; private $kashier_account_key; private $kashier_iframe_key; + private $kashier_token; public $app_name; private $verify_route_name; @@ -21,6 +23,7 @@ public function __construct() $this->kashier_mode = config("nafezly-payments.KASHIER_MODE"); $this->kashier_account_key = config("nafezly-payments.KASHIER_ACCOUNT_KEY"); $this->kashier_iframe_key = config("nafezly-payments.KASHIER_IFRAME_KEY"); + $this->kashier_token = config("nafezly-payments.KASHIER_TOKEN"); $this->currency = config('nafezly-payments.KASHIER_CURRENCY'); $this->app_name = config('nafezly-payments.APP_NAME'); $this->verify_route_name = config('nafezly-payments.VERIFY_ROUTE_NAME'); @@ -90,22 +93,43 @@ public function verify(Request $request): array if ($signature == $request["signature"]) { return [ 'success' => true, - 'payment_id'=>$request['transactionId'], + 'payment_id'=>$request['merchantOrderId'], 'message' => __('nafezly::messages.PAYMENT_DONE'), 'process_data' => $request->all() ]; } else { return [ 'success' => false, - 'payment_id'=>$request['transactionId'], + 'payment_id'=>$request['merchantOrderId'], 'message' => __('nafezly::messages.PAYMENT_FAILED'), 'process_data' => $request->all() ]; } + }else if($request['signature']==null){ + $url_mode = $this->kashier_mode == "live"?'':'test-'; + $response = Http::withHeaders([ + 'Authorization' => $this->kashier_token + ])->get('https://'.$url_mode.'api.kashier.io/payments/orders/'.$request['merchantOrderId'])->json(); + if(isset($response['response']['status']) && $response['response']['status']=="CAPTURED"){ + return [ + 'success' => true, + 'payment_id'=>$request['merchantOrderId'], + 'message' => __('nafezly::messages.PAYMENT_DONE'), + 'process_data' => $request->all() + ]; + }else{ + return [ + 'success' => false, + 'payment_id'=>$request['merchantOrderId'], + 'message' => __('nafezly::messages.PAYMENT_FAILED'), + 'process_data' => $request->all() + ]; + } + } else { return [ 'success' => false, - 'payment_id'=>$request['transactionId'], + 'payment_id'=>$request['merchantOrderId'], 'message' => __('nafezly::messages.PAYMENT_FAILED'), 'process_data' => $request->all() ];