2017 © Pedro Peláez
 

cakephp-plugin cakephp-sofortcom-plugin

CakePHP Sofort.com payment plugin

image

hakito/cakephp-sofortcom-plugin

CakePHP Sofort.com payment plugin

  • Saturday, September 13, 2014
  • by hakito
  • Repository
  • 1 Watchers
  • 0 Stars
  • 82 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

CakePHP-SofortCom-Plugin

Build Status Coverage Status, (*2)

CakePHP 4.x Sofort.com payment plugin, (*3)

Installation

If you are using composer simply add the plugin using the command, (*4)

composer require hakito/sofortcom-plugin

Otherwise download the plugin to app/Plugin/SofortCom. Add a PSR-4 compatible autoloader to your bootstrap., (*5)

Load the plugin in your bootstrap:, (*6)

public function bootstrap()
{
    // Call parent to load bootstrap from files.
    parent::bootstrap();

    $this->addPlugin(\SofortCom\Plugin::class, ['routes' => true]);
}

Creating tables

Create the database tables with the following command:, (*7)

bin/cake migrations migrate -p SofortCom

Configuration

In your app.local.php add an entry for SofortCom, (*8)

[
  'SofortCom' => [
    // enter your configuration key
    // you only can create a new configuration key by
    // creating a new Gateway project in your account at sofort.com
    'configkey' => 'dummy:key',

    // Encryption key for sending encrypted data to SofortCom
    'encryptionKey' => 'A_SECRET_KEY_MUST_BE_32_BYTES_LONG',

    // Default CurrencyCode.
    // You can override this when preparing the payment request.
    'currency' => 'EUR',

    // The conditions are used if you use the
    // SofortlibComponent::NeutralizeFee function
    'conditions' => [
        'fee' => 25,              // sofort.com fixed fee in cents
        'fee_relative' => '0.009' // relative sofort.com fee
    ]
  ]
];

Usage

In your payment handling controller:, (*9)

    // Load the component
    public function initialize()
    {
        parent::initialize();
        $this->loadComponent('SofortCom.Sofortlib');
    }

    // Sample checkout
    private function _checkoutSofortCom($orderId)
    {
        $this->Sofortlib->setAmount(12.34);
        $this->Sofortlib->setCurrencyCode('EUR');
        $this->Sofortlib->setReason('Buying Great Stuff', 'Order ' . $orderId); // Displayed as payment reason to the user
        $this->Sofortlib->setSuccessUrl('http://your-shop.example.com/success'); // The URL your clients are redirected upon success
        $this->Sofortlib->setAbortUrl('http://your-shop.example.com/abort'); // The URL your clients are redirected upon abort
        $this->Sofortlib->setShopId($orderId);

        try
        {
            $this->Sofortlib->PaymentRedirect();
        } catch (SofortLibException $ex) {
            Log::error(sprintf('SofortCom payment redirect errors: "%s"', var_export($ex->errors, true)));
            $this->Flash->set(__('Could not redirect to online banking (Error {0}). Please choose another payment method.', $ex->getMessage()));
            return $this->redirect('http://your-shop.example.com/recover');
        }
    }

Event handlers

You must implement at least the following eventhandler:, (*10)

SofortCom.Notify

\Cake\Event\EventManager::instance()->on('SofortCom.Notify',
function ($event, $args)
{
  // $args =
  // [
  //   'shop_id' => 'order123',                   // Some id defined by you upon payment initialization
  //   'notifyOn' => 'pending',                   // SofortCom notification URL suffix
  //   'transaction' => '99999-53245-5483-4891',  // SofortCom transaction id
  //   'time' => '2010-04-14T19:01:08+02:00',     // SofortCom timestamp of notification
  //   'data' => {object},                        // Instance of Sofort\SofortLib\TransactionData
  // ]


  return ['handled' => true]; // If you don't set the handled flag to true
                              // the plugin will throw an UnhandledNotificationException
});

SofortCom.NewTransaction

This event is optional and fired before the user is redirected to the payment URL. It provides the following arguments:, (*11)

$args =
[
  'transaction' => '99999-53245-5483-4891',    // SofortCom transaction id
  'payment_url' => 'http://sofort.com/example' // SofortCom payment redirect url
]

The Versions

13/09 2014

dev-master

9999999-dev https://github.com/hakito/CakePHP-SofortCom-Plugin

CakePHP Sofort.com payment plugin

  Sources   Download

GPL-2.0

The Requires

 

cakephp payment sofortcom