Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[paytrail] add lib and basic config. #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/config/parameters.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ parameters:

sofort.config_key: EDIT ME

paytrail.merchant_id: EDIT ME
paytrail.merchant_secret: EDIT ME

# configure if you want to use console create token commands
router.request_context.host: sandbox.payum.org
router.request_context.scheme: http
Expand Down
11 changes: 11 additions & 0 deletions app/config/payum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ payum:
factory: sofort
config_key: %sofort.config_key%

paytrail:
factory: paytrail
merchantId: %paytrail.merchant_id%
merchantSecret: %paytrail.merchant_secret%

foo_bar_gateway:
payum.action.capture: @acme_payment.foo_bar.capture
payum.action.status: @acme_payment.foo_bar.status
Expand All @@ -197,6 +202,12 @@ services:
tags:
- { name: payum.gateway_factory_builder, factory: redsys }

acme_payment.paytrail.gateway_factory:
class: Payum\Core\Bridge\Symfony\Builder\GatewayFactoryBuilder
arguments: [Paradigm\PayumPaytrail\PaytrailGatewayFactory]
tags:
- { name: payum.gateway_factory_builder, factory: paytrail }

acme_payment.jms_payment.gateway_factory:
class: Payum\Core\Bridge\Symfony\Builder\GatewayFactoryBuilder
arguments: [Payum\Bridge\JMSPayment\JmsGatewayFactory]
Expand Down
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,15 @@
"stripe/stripe-php": "^2.0",
"sofort/sofortlib-php": "^3.0",
"phpunit/phpunit": "^4.0",
"fabpot/php-cs-fixer": "^1.10"
"fabpot/php-cs-fixer": "^1.10",
"paradigm/payum-paytrail": "dev-master@dev"
},
"repositories": [
{
"type": "vcs",
"url": "[email protected]:Paradigmfi/PayumPaytrail.git"
}
],
"scripts": {
"post-install-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
Expand Down
61 changes: 53 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions src/Acme/PaymentBundle/Controller/SimplePaytrailController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
namespace Acme\PaymentBundle\Controller;

use Acme\PaymentBundle\Entity\PaymentDetails;
use Payum\Core\Payum;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Constraints\Range;
use Sensio\Bundle\FrameworkExtraBundle\Configuration as Extra;

class SimplePaytrailController extends Controller
{
/**
* @Extra\Route("/paytrail/prepare", name="acme_paytrail_prepare")
* @Extra\Template("AcmePaymentBundle::prepare.html.twig")
*/
public function prepareAction(Request $request)
{
$gatewayName = 'paytrail';

$form = $this->createPurchaseForm();
$form->handleRequest($request);
if ($form->isValid()) {
$data = $form->getData();

$storage = $this->getPayum()->getStorage(PaymentDetails::class);

$payment = $storage->create();
$payment['orderNumber'] = '12345678';
$payment['locale'] = 'fi_FI';
$payment['price'] = (float) $data['amount'];
$payment['currency'] = $data['currency'];

$storage->update($payment);

$captureToken = $this->getPayum()->getTokenFactory()->createCaptureToken(
$gatewayName,
$payment,
'acme_payment_details_view'
);

return $this->redirect($captureToken->getTargetUrl());
}

return ['form' => $form->createView()];
}

/**
* @return \Symfony\Component\Form\Form
*/
protected function createPurchaseForm()
{
return $this->createFormBuilder()
->add('amount', null, array(
'data' => 1.1,
'constraints' => array(new Range(array('max' => 2)))
))
->add('currency', null, array('data' => 'EUR'))

->getForm()
;
}

/**
* @return Payum
*/
protected function getPayum()
{
return $this->get('payum');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@
<a href="{{ path("acme_klarna_prepare_invoice") }}">Reserve&Activate Invoice</a>
</li>

<h3>Paytrail</h3>
<li>
<a href="{{ path("acme_paytrail_prepare") }}">Prepare</a>
</li>

<h3>Redsys\Sermepa</h3>
<li>
<a href="{{ path("acme_redsys_prepare") }}">Simple purchase</a>
Expand Down