Payum
Source🩷 Sponsor
  • Payum docs
  • Get started
  • Instant payment notification
  • ISO4217 or Currency Details
  • The Architecture
  • Your order integration
  • Supported Gateways
  • Storages
  • Debugging
  • Logging
  • Event Dispatcher
  • Configure gateways in backend
  • Working with sensitive information
  • Encrypt gateway configs stored in database
  • Mask credit card number
  • Develop a custom Payum gateway
  • Troubleshooting
  • Frameworks and e-commerce integration.
  • Payum vs Omnipay
  • How to contribute from sub repository
  • Examples
    • Paypal: Create Gateway
    • Paypal: Redirects
    • Handle redirect
    • Get Status
    • Stripe Js: Create gateway
    • Capture Payment
    • Get Http Reponse
    • Capture Credit Card
    • Authorise script
    • Capture Script
    • Done Script
    • index
    • Notify script
    • Payout Script
    • Refund script
  • Authorize-NET
    • AIM
      • Authorize.Net AIM: Get started
  • Be2Bill
    • Be2Bill Direct
    • Be2Bill Offsite
  • jms-payment-bridge
    • Get Started
  • Klarna
    • Checkout
      • Klarna Checkout: Get Started
    • Invoice
      • Klarna Invoice: Get Started
  • Laravel
    • Get Started
    • Blade Templating
    • Eloquent Storage
    • Payment done controller
    • Store gateway config in database
    • Examples
  • Offline
    • Get Started
  • Payex
    • Get Started
  • Paypal
    • Express Checkout
      • Get Started
      • Authorize order
      • Authorize token custom query parameters
      • Cancel recurring payment
      • Confirm order step
      • Recurring Payments Basics
    • IPN
      • Get Started
    • Masspay
      • Get Started
    • Pro Checkout
      • Get Started
    • Pro Hosted
      • Get Started
    • REST
      • Get Started
      • Credit Card Purchase
  • Silex
    • Get Started
    • Payment Done Controller
  • Sofort
    • Get Started
    • Disable Notifications
  • Stripe
    • Checkout
    • Direct
    • Stripe.js
    • Raw Capture
    • Store card and use later
    • Subscription Billing
  • Symfony
    • Get started
    • Authorize Payment
    • Configure payment in backend
    • Console commands
    • Container tags
    • Custom Action
    • Custom API usage
    • Creating custom view for payment page
    • Custom purchase examples
    • Debugging
    • Encrypt gateway configs stored in database
    • ISO4217 or Currency Details
    • Purchase done action
    • Refund Payment
    • Sandbox
    • Storages
    • Configuration Reference
    • Custom Purchase Examples
      • Authorize.NET AIM
      • Be2Bill onsite
      • Be2Bill Credit Card
      • Klarna Checkout
      • Klarna Invoice
      • Payex
      • Paypal Express Checkout
      • Paypal Pro Checkout
      • Paypal via Omnipay
      • Stripe checkout
      • Stripe.js
      • Stripe via Omnipay
Powered by GitBook
On this page
  • Install
  • config.php
  • prepare.php
  • capture.php
  • done.php
  • Supporting Payum
Edit on GitHub

Get started

PreviousPayum docsNextInstant payment notification

Last updated 1 year ago

Here we describe basic steps required by all supported gateways. We are going to setup models, storages, a security layer and so on. All that stuff will be used later.

Note: If you are working with Symfony framework look read the bundle's instead.

Note: If you are working with Laravel framework look read the instead.

Install

The preferred way to install the library is using . Run composer require to add dependencies to composer.json:

php composer.phar require payum/offline php-http/guzzle7-adapter

Note: Where payum/offline is a php payum extension, you can for example change it to payum/paypal-express-checkout-nvp or payum/stripe. Look at to find out what you can use.

Note: Use payum/payum if you want to install all gateways at once.

Note: Use php-http/guzzle7-adapter is just an example. You can use any of .

Before we configure payum, let's look at the flow diagram. This flow is same for all gateways so once you familiar with it any other gateways could be added easily.

How payum works

config.php

Here we can put our gateways, storages. Also we can configure security components. The config.php has to be included to all left files.

<?php
//config.php

use Payum\Core\PayumBuilder;
use Payum\Core\Payum;
use Payum\Core\Model\Payment;

$paymentClass = Payment::class;

/** @var Payum $payum */
$payum = (new PayumBuilder())
    ->addGateway('aGateway', [
        'factory' => 'offline',
    ])

    ->getPayum()
;

Note: Consider using something other than FilesystemStorage in production.

prepare.php

<?php
// prepare.php

include __DIR__.'/config.php';

$gatewayName = 'aGateway';

/** @var \Payum\Core\Payum $payum */
$storage = $payum->getStorage($paymentClass);

$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($gatewayName, $payment, 'done.php');

header("Location: ".$captureToken->getTargetUrl());

capture.php

When the preparation is done a user is redirect to capture.php. Here's an example of this file. You can just copy\past the code. It has to work for all gateways without any modification from your side.

<?php
//capture.php

use Payum\Core\Request\Capture;
use Payum\Core\Reply\HttpRedirect;
use Payum\Core\Reply\HttpPostRedirect;

include __DIR__.'/config.php';

/** @var \Payum\Core\Payum $payum */
$token = $payum->getHttpRequestVerifier()->verify($_REQUEST);
$gateway = $payum->getGateway($token->getGatewayName());

/** @var \Payum\Core\GatewayInterface $gateway */
if ($reply = $gateway->execute(new Capture($token), true)) {
    if ($reply instanceof HttpRedirect) {
        header("Location: ".$reply->getUrl());
        die();
    } elseif ($reply instanceof HttpPostRedirect) {
        echo $reply->getContent();
        die();
    }

    throw new \LogicException('Unsupported reply', null, $reply);
}

/** @var \Payum\Core\Payum $payum */
$payum->getHttpRequestVerifier()->invalidate($token);

header("Location: ".$token->getAfterUrl());

done.php

<?php
// done.php

use Payum\Core\Request\GetHumanStatus;

include __DIR__.'/config.php';

/** @var \Payum\Core\Payum $payum */
$token = $payum->getHttpRequestVerifier()->verify($_REQUEST);
$gateway = $payum->getGateway($token->getGatewayName());

// you can invalidate the token. The url could not be requested any more.
// $payum->getHttpRequestVerifier()->invalidate($token);

// Once you have token you can get the model from the storage directly. 
//$identity = $token->getDetails();
//$payment = $payum->getStorage($identity->getClass())->find($identity);

// or Payum can fetch the model for you while executing a request (Preferred).
$gateway->execute($status = new GetHumanStatus($token));
$payment = $status->getFirstModel();

header('Content-Type: application/json');
echo json_encode([
    'status' => $status->getValue(),
    'order' => [
        'total_amount' => $payment->getTotalAmount(),
        'currency_code' => $payment->getCurrencyCode(),
        'details' => $payment->getDetails(),
    ],
]);

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:

As you can see we have to create some php files: config.php, prepare.php, capture.php and done.php. At the end you will have the complete solution and it would be other gateways. Let's start from the config.php and continue with rest after:

Note: There are other available. Such as Doctrine ORM\MongoODM.

At this stage we have to create an order. Add some information into it. Create a capture token and delegate the job to script. Here's an offline gateway example:

Note: There are examples for all .

Note: Find out more about capture script in the .

After the capture did its job you will be redirected to . The script always redirects you to done.php no matter the payment was a success or not. In done.php we may check the payment status, update the model, dispatch events and so on.

Note: Find out more about done script in the .

much easier to add
storages
capture.php
supported gateways
dedicated chapter
done.php
capture.php
dedicated chapter
Become a sponsor
composer
supported gateways
these adapters
documentation
documentation