lib/boab/ecommerce-bundle/src/PaymentMethod/MobileMoney.php line 19

Open in your IDE?
  1. <?php 
  2. namespace Boab\EcommerceBundle\PaymentMethod;
  3. use Boab\EcommerceBundle\Entity\OrderInterface;
  4. use Boab\EcommerceBundle\PaymentMethod\Exception\PaymentFailedException;
  5. use Boab\EcommerceBundle\Repository\OrderRepositoryInterface;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\Routing\RouterInterface;
  8. use OVAC\HubtelPayment\Config;
  9. use OVAC\HubtelPayment\Api\Transaction\ReceiveMoney;
  10. class MobileMoney implements PaymentMethodInterface
  11. {
  12.     private $router;
  13.     private $clientId;
  14.     private $clientSecret;
  15.     public function __construct(
  16.         RouterInterface $router,
  17.         OrderRepositoryInterface $orderRepository,
  18.         string $clientId,
  19.         string $clientSecret
  20.     )
  21.     {
  22.         $this->router $router;
  23.         $this->orderRepository $orderRepository;
  24.         $this->clientId $clientId;
  25.         $this->clientSecret $clientSecret;
  26.     }
  27.     
  28.     public function supports(string $type):bool
  29.     {
  30.         return $type === $this->getIdentifier();
  31.     }
  32.     public function execute(OrderInterface $order)
  33.     {
  34.         $paymentMethod $order->getPaymentMethod();
  35.         $callback $this->router->generate('payment_validate_url', ['reference'=>$order->getOrderId(), 'payment_method'=>$paymentMethod]);
  36.         // First Create configuration with your Hubtel Developer Credentials
  37.         // The Account Number, ClientID and ClientSecret accordingly.
  38.         /*
  39.         try{
  40.             $config = new Config('0553595215', $this->clientId, $this->clientSecret);
  41.             $payment =  ReceiveMoney::from($order->getContactNumber())          //- The phone number to send the prompt to.
  42.                 ->amount(2.00)                    //- The exact amount value of the transaction
  43.                 ->description('Online Purchase')    //- Description of the transaction.
  44.                 ->customerName($order->getFirstName().' '.$order->getLastName())     //- Name of the person making the payment.
  45.                 ->callback($callback) //- The URL to send callback after payment.    
  46.                 ->channel('mtn-gh')                 //- The mobile network Channel.
  47.                 ->injectConfig($config)             //- Inject the configuration
  48.                 ->run();  
  49.             dump($payment);
  50.         }catch(\Exception $e){
  51.             dump($e);
  52.             throw new PaymentFailedException($e->getMessage(), 400);
  53.         }
  54.         */
  55.         return $this->router->generate('app_mobile_payment', ['reference'=>$order->getOrderId(), 'payment_method'=>$paymentMethod]);        
  56.     }
  57.     public function completePayment(Request $requestOrderInterface $order)
  58.     {   
  59.       return $order;
  60.     }
  61.     public function getIdentifier(): string
  62.     {
  63.         return 'MobileMoney';
  64.     }
  65. }