amonger / laravel-payment-commands
Payment commands for laravel
Requires
- php: ^7.0
- omnipay/omnipay: ^2.3
README
This repo contains a set of commands which allow you to use Laravels command bus to take payments through paypal express (with more to come).
Setting up
Initially you're going to have to find your api details, which you can find under your profile page on paypal.
You'll need to add these to your .env file
PAYPAL_USERNAME=username
PAYPAL_PASSWORD=password
PAYPAL_SIGNATURE=signature
#PAYPAL_TEST_MODE=true # Be sure to use this if accessing a sandbox!
You'll then need to add the gateway service provider to your app.php. This binds the provider to the GatewayInterface.
'providers' => [ ... PaymentCommands\Paypal\Providers\GatewayServiceProvider::class ],
Dispatching Commands
After this has been added, you're good to go! Just fire the command bus in your controller for handling the payment. This will return the redirect url, which you can then redirect to.
public function index() { $cancelUrl = url('/cancel'); $returnUrl = url('/capture'); $currency = 'GBP'; $items = [ [ 'price' => 200, 'description' => 'A bike', 'quantity' => 1 ] ]; $redirectUrl = $this->dispatch(new MakePayment($items, $currency, $cancelUrl, $returnUrl)); return redirect($redirectUrl); }
After the payment has been completed, you redirect the user back to your website.
public function capture() { $this->dispatch(new CapturePayment(Input::get('token'), Input::get('payerID'))); }
Extending
Each stage of the command bus fires an event which you can hook into.
You can read about how to implement this by looking at the Event Documentation