Skip to content

Commit

Permalink
update docs, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
makasim committed Sep 24, 2015
1 parent db02140 commit 329ce79
Showing 1 changed file with 18 additions and 71 deletions.
89 changes: 18 additions & 71 deletions Resources/docs/get-it-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,79 +14,26 @@ php composer.phar require payum/klarna-checkout

## config.php

Now configuration. Let's start from defining some models.
First one is a `PaymentDetails`.
It will storage all the information related to the payment:

```php
<?php
namespace App\Model;

use Payum\Core\Model\ArrayObject;

class PaymentDetails extends ArrayObject
{
protected $id;
}
```

The other one is `PaymentSecurityToken`.
We will use it to secure our payment operations:

```php
<?php
namespace App\Model;

use Payum\Core\Model\Token;

class PaymentSecurityToken extends Token
{
}
```

_**Note**: We provide Doctrine ORM\MongoODM mapping for these models to ease usage with doctrine storage._

Now we are ready to configure all the stuff:
We have to only add the gateway factory. All the rest remain the same:

```php
<?php
//config.php

use Payum\Core\Bridge\PlainPhp\Security\HttpRequestVerifier;
use Payum\Core\Bridge\PlainPhp\Security\TokenFactory;
use Payum\Core\Registry\SimpleRegistry;
use Payum\Core\Storage\FilesystemStorage;
use Payum\Core\Security\GenericTokenFactory;
use Payum\Klarn\Checkout\KlarnaCheckoutGatewayFactory;

$tokenStorage = new FilesystemStorage('/path/to/storage', 'App\Model\PaymentSecurityToken', 'hash');
$requestVerifier = new HttpRequestVerifier($tokenStorage);

$detailsClass = 'App\Model\PaymentDetails';

$storages = array(
$detailsClass => new FilesystemStorage('/path/to/storage', $detailsClass, 'id')
);

$gateways = array();
use Payum\Core\PayumBuilder;
use Payum\Core\Payum;

$klarnaCheckoutFactory = new KlarnaCheckoutGatewayFactory();
$gateways['klarna_checkout'] => $klarnaCheckoutFactory->create(array(
'merchant_id' => 'EDIT IT',
'secret' => 'EDIT IT',
));
/** @var Payum $payum */
$payum = (new PayumBuilder())
->addDefaultStorages()
->addGatewayConfig('klarna', [
'factory' => 'klarna_checkout'
'merchant_id' => 'EDIT IT',
'secret' => 'EDIT IT',
])

$payum = new SimpleRegistry($gateways, $storages);

$tokenFactory = new GenericTokenFactory(
new TokenFactory($tokenStorage, $payum),
array(
'capture' => 'capture.php',
'notify' => 'notify.php',
'authorize' => authorize.php',
'refund' => 'refund.php',
)
);
->getPayum()
;
```

An initial configuration for Payum basically wants to ensure we have things ready to be stored such as
Expand All @@ -101,22 +48,22 @@ We need to add gateway factory and payment details storage.

```php
<?php

// prepare.php

use Payum\Core\Model\ArrayObject;

include 'config.php';

$storage = $payum->getStorage($detailsClass);
$storage = $this->getPayum()->getStorage('Acme\PaymentBundle\Model\PaymentDetails');
$storage = $this->getPayum()->getStorage(ArrayObject::class);

$details = $storage->create();
$details['purchase_country'] = 'SE';
$details['purchase_currency'] = 'SEK';
$details['locale'] = 'sv-se';
$storage->update($details);

$captureToken = $tokenFactory->createCaptureToken('klarna_checkout', $details, 'done.php');
$notifyToken = $tokenFactory->createNotifyToken('klarna_checkout', $details);
$captureToken = $payum->getTokenFactory()->createCaptureToken('klarna', $details, 'done.php');
$notifyToken = $payum->tokenFactory()->createNotifyToken('klarna', $details);

$details['merchant'] = array(
'terms_uri' => 'http://example.com/terms',
Expand Down

0 comments on commit 329ce79

Please sign in to comment.