<?php
namespace Boab\EcommerceBundle\PaymentMethod;
use Boab\EcommerceBundle\Entity\OrderInterface;
use Boab\EcommerceBundle\PaymentMethod\Exception\PaymentFailedException;
use Boab\EcommerceBundle\Repository\OrderRepositoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RouterInterface;
use OVAC\HubtelPayment\Config;
use OVAC\HubtelPayment\Api\Transaction\ReceiveMoney;
class MobileMoney implements PaymentMethodInterface
{
private $router;
private $clientId;
private $clientSecret;
public function __construct(
RouterInterface $router,
OrderRepositoryInterface $orderRepository,
string $clientId,
string $clientSecret
)
{
$this->router = $router;
$this->orderRepository = $orderRepository;
$this->clientId = $clientId;
$this->clientSecret = $clientSecret;
}
public function supports(string $type):bool
{
return $type === $this->getIdentifier();
}
public function execute(OrderInterface $order)
{
$paymentMethod = $order->getPaymentMethod();
$callback = $this->router->generate('payment_validate_url', ['reference'=>$order->getOrderId(), 'payment_method'=>$paymentMethod]);
// First Create configuration with your Hubtel Developer Credentials
// The Account Number, ClientID and ClientSecret accordingly.
/*
try{
$config = new Config('0553595215', $this->clientId, $this->clientSecret);
$payment = ReceiveMoney::from($order->getContactNumber()) //- The phone number to send the prompt to.
->amount(2.00) //- The exact amount value of the transaction
->description('Online Purchase') //- Description of the transaction.
->customerName($order->getFirstName().' '.$order->getLastName()) //- Name of the person making the payment.
->callback($callback) //- The URL to send callback after payment.
->channel('mtn-gh') //- The mobile network Channel.
->injectConfig($config) //- Inject the configuration
->run();
dump($payment);
}catch(\Exception $e){
dump($e);
throw new PaymentFailedException($e->getMessage(), 400);
}
*/
return $this->router->generate('app_mobile_payment', ['reference'=>$order->getOrderId(), 'payment_method'=>$paymentMethod]);
}
public function completePayment(Request $request, OrderInterface $order)
{
return $order;
}
public function getIdentifier(): string
{
return 'MobileMoney';
}
}