PayumBundle Documentation

repository·master·Indexed 20 days ago

https://github.com/payum/payumbundle

PayumBundle integrates the Payum payment library into the Symfony framework. It provides a configuration layer for gateways and storages, secured capture controllers, and CLI tools for managing payment tokens and debugging gateways. The bundle supports various storage drivers including filesystem, ORM, and MongoDB, and integrates with gateways such as PayPal, Stripe, Authorize.Net, Be2Bill, Payex, Klarna, and Omnipay.

Tokens
31.5K
Snippets
105
Records
112
Agent score
69%

What's inside PayumBundle

  1. Migrate from 2.0 to 2.1

    master

    When upgrading from version 2.0 to 2.1, several global services have been removed. Instead of using these services directly, you must now use the gateway's configuration to overwrite them.

    Removed services:

    • payum.http_client
    • payum.iso4217
    • payum.guzzle_client
  2. Refund a payment

    master

    To refund a previously purchased order, retrieve the appropriate gateway (e.g., 'offline') and execute a Refund request using the payment object. After the refund request, you should execute a GetHumanStatus request to verify if the refund was successful. If isRefunded() returns false, inspect the payment's details via $payment->getDetails() to diagnose the failure.

    <?php
    
    use Payum\Core\Request\Refund;
    use Payum\Core\Request\GetHumanStatus;
    
    $gateway = $this->payum->getGateway('offline');
    
    // Execute the refund
    $gateway->execute(new Refund($payment));
    
    // Check the status of the payment
    $status = $gateway->execute(new GetHumanStatus($payment));
    
    if ($status->isRefunded()) {
        // Refund went well
    } else {
        // Something went wrong. Check details to find out why
        var_dump($payment->getDetails());
    }
  3. Configure Propel storage

    master

    To use Propel, you need to build your schema (either your own or by copying the one from Payum\Core\Bridge\Propel\Resources\config\schema.xml) and implement the required model classes.

    1. Implement a Token class extending the generated BaseToken and implementing Payum\Core\Security\TokenInterface.
    2. Implement a Payment class extending the generated BasePayment and implementing Payum\Core\Model\PaymentInterface.
    3. Register them in payum.yml using the propel1 or propel2 driver.
    payum:
        security:
            token_storage:
                Acme\\DemoBundle\\Model\\Token: { propel1: ~ }
        storages:
            Acme\\DemoBundle\\Model\\Payment: { propel1: ~ }
  4. Implement a custom storage

    master

    If the built-in storages do not meet your needs, you can implement your own by implementing the Payum\Core\Storage\StorageInterface.

    1. Create a class that implements StorageInterface.
    2. Register your class as a service in your container.
    3. Map your model to your custom storage service in payum.yml using the syntax model_class: { custom: service_id }.
    namespace Acme\\PaymentBundle\\Payum\\Storage;
    
    use Payum\\Core\\Storage\\StorageInterface;
    
    class CustomStorage implements StorageInterface
    {
      // implement interface methods.
    }
    # config/packages/payum.yml
    services:
        acme.payment.payum.storage.custom:
            class: Acme\\PaymentBundle\\Payum\\Storage\\CustomStorage
    
    payum:
        storages:
            Acme\\PaymentBundle\\Model\\Foo:
                custom: acme.payment.payum.storage.custom
  5. Migrate from 0.8 to 0.9

    master

    Upgrading from 0.8 to 0.9 includes changes to how actions are loaded and how configuration is structured:

    • Action Loading: Payment factories no longer create action services. Instead, they use actions defined in the payment/foo.xml file via tags.
    • Configuration Simplification: The api.options sub-option has been removed. Options are now moved to the root of the factory section.
    • Storage Configuration Migration: The storages section has moved from inside a context to the root payum section. By default, storages are now added to all payments.
    • Renamed Factory: be2bill no longer supports onsite payments; use the be2bill_onsite factory instead.
    • Interface Changes: The signature of StorageFactoryInterface::create has changed; the second contextName and fourth paymentId arguments were removed.
    ### Configuration Migration Example
    
    **Before (0.8):**
    ```yml
    payum:
        a_context:
            a_factory:
                api:
                    options:
                        foo: foo
                        bar: bar

    After (0.9):

    payum:
        a_context:
            a_factory:
                foo: foo
                bar: bar

    Storage Migration Example

    Before (0.8):

    payum:
        a_context:
            a_factory:
                storages:
                    Acme\PaymentBundle\Entity\PaymentDetails:
                        doctrine:
                            driver: orm

    After (0.9):

    payum:
        storages:
            Acme\PaymentBundle\Entity\PaymentDetails:
                payment:
                    contexts: [a_factory]
                doctrine: orm
                    
        a_context:
            a_factory: 
  6. Configure dynamic gateways in the backend

    master

    To allow managing gateways (adding, deleting, or changing credentials) via a backend interface instead of static YAML files, you must use dynamic gateways. This requires implementing a storage mechanism for gateway configurations.

    1. Create a Configuration Entity: Create a class that implements Payum\Core\Model\GatewayConfigInterface. If using Doctrine ORM, extend Payum\Core\Model\GatewayConfig.
    2. Configure Payum: Register your entity in the payum.yml configuration file under dynamic_gateways and specify the config_storage.
    3. Admin Integration: This guide uses Sonata Admin to provide the UI. Once configured, gateways can be managed via the Sonata dashboard.

    Note: If a gateway is defined in both config.yml and the backend storage with the same name, the backend configuration takes precedence.

    <?php
    namespace Acme\PaymentBundle\Entity;
    
    use Doctrine\ORM\Mapping as ORM;
    use Payum\Core\Model\GatewayConfig as BaseGatewayConfig;
    
    /**
     * @ORM\Table
     * @ORM\Entity
     */
    class GatewayConfig extends BaseGatewayConfig
    {
        /**
         * @ORM\Column(name="id", type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="IDENTITY")
         */
        protected int $id;
    }