Examples
Paypal Express checkout
Described in Get it started
Payment model
Configuration
$ php composer.phar require payum/payum-laravel-package payum/offline
// bootstrap/start.php
App::resolving('payum.builder', function(\Payum\Core\PayumBuilder $payumBuilder) {
$payumBuilder
->addGateway('offline', ['factory' => 'offline'])
;
});
Prepare payment
<?php
// app/controllers/PaymentController.php
use Payum\LaravelPackage\Controller\PayumController;
class PaymentController extends PayumController
{
public function preparePayment()
{
$storage = $this->getPayum()->getStorage('Payum\Core\Model\Payment');
$payment = $storage->create();
$payment->setNumber(uniqid());
$payment->setCurrencyCode('EUR');
$payment->setTotalAmount(123); // 1.23 EUR
$payment->setDescription('A description');
$payment->setClientId('anId');
$payment->setClientEmail('foo@example.com');
$payment->setDetails(array(
// put here any fields in a gateway format.
// for example if you use Paypal ExpressCheckout you can define a description of the first item:
// 'L_PAYMENTREQUEST_0_DESC0' => 'A desc',
));
$storage->update($payment);
$captureToken = $payum->getTokenFactory()->createCaptureToken('offline', $payment, 'payment_done');
return \Redirect::to($captureToken->getTargetUrl());
}
}
Stripe.Js
Configuration
$ php composer.phar require payum/payum-laravel-package stripe/stripe-php payum/stripe
// bootstrap/start.php
App::resolving('payum.builder', function(\Payum\Core\PayumBuilder $payumBuilder) {
$payumBuilder
->addGateway('stripe_js', [
'factory' => 'stripe_js',
'publishable_key' => 'EDIT ME',
'secret_key' => 'EDIT ME',
])
;
});
Prepare payment
<?php
// app/controllers/StripeController.php
use Payum\LaravelPackage\Controller\PayumController;
class StripeController extends PayumController
{
public function prepareJs()
{
$storage = $this->getPayum()->getStorage('Payum\Core\Model\ArrayObject');
$details = $storage->create();
$details['amount'] = '100';
$details['currency'] = 'USD';
$details['description'] = 'a desc';
$storage->update($details);
$captureToken = $this->getPayum()->getTokenFactory()->createCaptureToken('stripe_js', $details, 'payment_done');
return \Redirect::to($captureToken->getTargetUrl());
}
}
Stripe Checkout
Configuration
$ php composer.phar require payum/stripe payum/payum-laravel-package stripe/stripe-php
// bootstrap/start.php
App::resolving('payum.builder', function(\Payum\Core\PayumBuilder $payumBuilder) {
$payumBuilder
->addGateway('stripe_checkout', [
'factory' => 'stripe_checkout',
'publishable_key' => 'EDIT ME',
'secret_key' => 'EDIT ME',
])
;
});
Prepare payment
<?php
// app/controllers/StripeController.php
use Payum\LaravelPackage\Controller\PayumController;
class StripeController extends PayumController
{
public function prepareCheckout()
{
$storage = $this->getPayum()->getStorage('Payum\Core\Model\ArrayObject');
$details = $storage->create();
$details['amount'] = '100';
$details['currency'] = 'USD';
$details['description'] = 'a desc';
$storage->update($details);
$captureToken = $this->getPayum()->getTokenFactory()->createCaptureToken('stripe_checkout', $details, 'payment_done');
return \Redirect::to($captureToken->getTargetUrl());
}
}
Stripe Direct (via Omnipay)
Configuration
$ php composer.phar require payum/omnipay-bridge payum/payum-laravel-package omnipay/stripe
// bootstrap/start.php
App::resolving('payum.builder', function(\Payum\Core\PayumBuilder $payumBuilder) {
$payumBuilder
->addGateway('stripe_direct', [
'factory' => 'omnipay_direct',
'type' => 'Stripe',
'options' => array(
'apiKey' => 'EDIT ME',
'testMode' => true,
),
])
;
});
Prepare payment
<?php
// app/controllers/OmnipayController.php
use Payum\LaravelPackage\Controller\PayumController;
class OmnipayController extends PayumController
{
public function prepareDirect()
{
$storage = $this->getPayum()->getStorage('Payum\Core\Model\ArrayObject');
$details = $storage->create();
$details['amount'] = '10.00';
$details['currency'] = 'USD';
$storage->update($details);
$captureToken = $this->getPayum()->getTokenFactory()->createCaptureToken('stripe_direct', $details, 'payment_done');
return \Redirect::to($captureToken->getTargetUrl());
}
}
Supporting Payum
Payum is an MIT-licensed open source project with its ongoing development made possible entirely by the support of community and our customers. If you'd like to join them, please consider:
Last updated