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); }
} 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'); } public function callVerifyRequest(PaymentNeeds $needs, Request $request = null) { // verify the payment and return response return new PaymentVerifyResponse('TRANSACTION_ID'); } } $manager->extend('example', function () { return new ExampleProvider(); }); /** * PaymentRequestNeeds * you can create new PaymentRequestNeeds * and customize it for your own provider * * for more information read Default payment providers */ $requestNeeds = new PaymentRequestNeeds(); $requestNeeds->setAmount(1000); $requestNeeds->setReturnUrl('YOUR_CALLBACK_URL'); $requestNeeds->set('attr', 'value'); // Call with provider name // by this, you can change provider on-the-fly $manager->provider('example')->callPaymentRequest($requestNeeds);