public function testMagicMethods() { $manager = new GatewayManager($this->config); $manager->extend('example', function () { return new ExampleProvider(); }); $manager->setDefaultProvider('example'); $response = $manager->callPaymentRequest(new \Laratalks\PaymentGateways\ValueObjects\PaymentRequestNeeds()); $this->assertTrue($response instanceof PaymentRequestResponse); }
use Laratalks\PaymentGateways\GatewayManager; use Laratalks\PaymentGateways\Providers\ProviderInterface; use Laratalks\PaymentGateways\ValueObjects\PaymentNeeds; use Laratalks\PaymentGateways\ValueObjects\PaymentRequestNeeds; use Laratalks\PaymentGateways\ValueObjects\PaymentRequestResponse; use Laratalks\PaymentGateways\ValueObjects\PaymentVerifyResponse; use Symfony\Component\HttpFoundation\Request; $config = (new Config())->addProvider(new ProviderConfig('upal', 'fknnfgloshgwl353dkvjdoif'))->addProvider(new ProviderConfig('zarinpal', 'nafngwithtgngt'))->setDefaultProvider('upal'); $proxy = new ProxyConfig(); $proxy->setType(ProxyConfig::TYPE_HTTP); $proxy->setHost('localhost'); $proxy->setPort(8123); $proxy->setEnabled(true); $config->setProxy($proxy); // The facade to all abilities $manager = new GatewayManager($config); /** * Extending your own provider */ class ExampleProvider implements ProviderInterface { public function getName() { return 'example'; } public function callPaymentRequest(PaymentRequestNeeds $needs) { // call payment request and get response // you must generate payment url // for redirecting customer to payment gateway return new PaymentRequestResponse('PAYMENT_URL');