diff --git a/src/Controllers/PaymobController.php b/src/Controllers/PaymobController.php index 3d75fa3..7573860 100644 --- a/src/Controllers/PaymobController.php +++ b/src/Controllers/PaymobController.php @@ -5,52 +5,8 @@ namespace MG\Paymob\Controllers; use App\Http\Controllers\Controller; -use MG\Paymob\Paymob; class PaymobController extends Controller { - private $payMob = null; - public function __construct(Paymob $payMob) - { - $this->payMob = $payMob; - } - - /** - * @TODO will be removed! - */ - public function test() - { - $billingData = [ - 'apartment' => 'NA', - 'email' => 'test@test.com', - 'floor' => 'NA', - 'first_name' => 'test', - 'street' => 'NA', - 'building' => 'NA', - 'phone_number' => '01234567890', - 'shipping_method' => 'NA', - 'postal_code' => 'NA', - 'city' => 'NA', - 'country' => 'NA', - 'last_name' => 'NA', - 'state' => 'NA', - ]; - - $data = [ - 'delivery_needed' => false, // default false - 'amount_cents' => 10000, // default 0 - 'items' => [], //default [] - 'expiration' => 3600, // default 3600 - 'merchant_order_id' => '123', // default null - 'billing_data' => $billingData, // required - 'currency' => 'EGP', // default EGP - ]; - - // $token = 'ZXlKMGVYQWlPaUpLVjFRaUxDSmhiR2NpT2lKSVV6VXhNaUo5LmV5SmpiR0Z6Y3lJNklrMWxjbU5vWVc1MElpd2ljR2hoYzJnaU9pSTBPR0V4WVRJeU1tSmtORGswWkRSallUZGpNVFkzWXprd01qZzROV1U0T1RRM016UXhaamRoWWpBME5HUTBNakE1WkdKbFkySXdNR0kwTlRJeVlqazRJaXdpY0hKdlptbHNaVjl3YXlJNk16Y3lOREV4TENKbGVIQWlPakUyTmpFME56UXpPRGg5LlNoV1ltWkc3UkpQOHdXelQycEkxaUdoVU92S1RCSUZ0M2hIdmU1cU5qeXV0b2JQcHo5ZUZNdHR4Ql9hWERfb0VKX2NLNVU1Um5JU0U4N2x0N2IzWi1B'; - - $iframeUrl = $this->payMob->makePayment($data); - - return redirect()->to($iframeUrl); - } } diff --git a/src/Controllers/TransactionCallbackController.php b/src/Controllers/TransactionCallbackController.php index 77c30da..eb9b813 100644 --- a/src/Controllers/TransactionCallbackController.php +++ b/src/Controllers/TransactionCallbackController.php @@ -12,18 +12,20 @@ class TransactionCallbackController extends Controller /** * Handle Transaction Callback Processed. * + * @param Request $request * @return void */ - public function processed(Request $request) + public function processed(Request $request): void { } /** * Handle Transaction Callback Response. * + * @param Request $request * @return void */ - public function response(Request $request) + public function response(Request $request): void { } } diff --git a/src/Facades/Paymob.php b/src/Facades/Paymob.php index daac0ce..fd90521 100644 --- a/src/Facades/Paymob.php +++ b/src/Facades/Paymob.php @@ -13,7 +13,7 @@ class Paymob extends Facade * * @return string */ - protected static function getFacadeAccessor() + protected static function getFacadeAccessor(): string { return 'paymob'; } diff --git a/src/Paymob.php b/src/Paymob.php index 2ead94b..6c24c5b 100644 --- a/src/Paymob.php +++ b/src/Paymob.php @@ -16,14 +16,14 @@ class Paymob * * @var string */ - protected $integrationId; + protected mixed $integrationId; /** * The Iframe ID. * * @var string */ - protected $iframeId; + protected mixed $iframeId; /** * Constructor. @@ -34,26 +34,6 @@ public function __construct(string $integrationId = null, string $iframeId = nul $this->iframeId = $iframeId ?: config('paymob.auth.iframe_id'); } - /** - * Set The Integration ID. - */ - public function setIntegrationId(string $integrationId): self - { - $this->integrationId = $integrationId; - - return $this; - } - - /** - * Set The Iframe ID. - */ - public function setIframeId(string $iframeId): self - { - $this->iframeId = $iframeId; - - return $this; - } - /** * Paymob Authentication. */ @@ -118,15 +98,17 @@ public function getPaymentKey(string $token, int $amountCents, int $expiration, } /** - * Make payment for API (moblie clients). + * Make payment for API (mobile clients). * Return iframe_url. * - * @param string $paymentToken + * @param array $data + * @param null $mobileWallet + * @return string */ public function makePayment(array $data, $mobileWallet = null): string { // step 1 -> Authentication - $authToken = $this->autheticate(); + $authToken = $this->authenticate(); // step 2 -> Order Registration $orderId = $this->registerOrder($authToken, $data); @@ -134,6 +116,7 @@ public function makePayment(array $data, $mobileWallet = null): string // step 3 => Get Payment Key $paymentToken = $this->createPaymentToken($authToken, $orderId, $data); + //@TODO: should be refactored! if ($mobileWallet) { $walletResponse = $this->prepareWalletRedirectionUrl($paymentToken, $mobileWallet); @@ -144,75 +127,21 @@ public function makePayment(array $data, $mobileWallet = null): string return $this->buildIframeUrl($paymentToken); } - /** - * Capture authed order. - * - * @param string $token - * @param int $transactionId - * @param int amount - */ - public function capture($token, $transactionId, $amount): array - { - return []; - } - - /** - * Get paymob all orders. - * - * @param string $authToken - * @param string $page - */ - public function getOrders($authToken, $page = 1): Response - { - } - - /** - * Get paymob order. - * - * @param string $authToken - * @param int $orderId - */ - public function getOrder($authToken, $orderId): Response - { - } - - /** - * Get Paymob all transactions. - * - * @param string $authToken - * @param string $page - */ - public function getTransactions($authToken, $page = 1): Response - { - } - - /** - * Get Paymob transaction. - * - * @param string $authToken - * @param int $transactionId - */ - public function getTransaction($authToken, $transactionId): Response - { - } - /** * authenticate request * return authToken. */ - private function autheticate(): string + private function authenticate(): string { $authResponse = $this->auth(); - $authToken = $authResponse['token']; - - return $authToken; + return $authResponse['token']; } /** * register order request * return orderId. */ - private function registerOrder(string $authToken, array $data): string + private function registerOrder(string $authToken, array $data): int { $deliveryNeeded = $data['delivery_needed'] ?? false; $amountCents = $data['amount_cents'] ?? 0; @@ -228,11 +157,10 @@ private function registerOrder(string $authToken, array $data): string * create payment token request * return paymentToken. */ - private function createPaymentToken(string $authToken, string $orderId, array $data): string + private function createPaymentToken(string $authToken, int $orderId, array $data): string { $amountCents = (isset($data['amount_cents']) && $data['amount_cents']) ? $data['amount_cents'] : 0; $expiration = (isset($data['expiration']) && $data['expiration']) ? $data['expiration'] : 3600; - $merchantOrderId = (isset($data['merchant_order_id']) && $data['merchant_order_id']) ? $data['merchant_order_id'] : null; $billingData = (isset($data['billing_data']) && $data['billing_data']) ? $data['billing_data'] : []; $currency = (isset($data['currency']) && $data['currency']) ? $data['currency'] : 'EGP'; @@ -255,14 +183,11 @@ private function buildIframeUrl(string $paymentToken): string /** * Send order to paymob servers. * - * @param string $token - * @param bool $deliveryNeeded - * @param int $amountCents - * @param array $items - * + * @param string $paymentToken + * @param string|null $mobileWallet * @return array */ - public function prepareWalletRedirectionUrl(string $paymentToken, string $mobileWallet = null) + public function prepareWalletRedirectionUrl(string $paymentToken, string $mobileWallet = null): array { $json = [ 'payment_token' => $paymentToken,