Skip to content

Commit 579ce13

Browse files
author
Dalibor Karlović
committed
feature(lib) initial import
0 parents  commit 579ce13

18 files changed

+973
-0
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
indent_size = 4
8+
indent_style = space
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

.gitattributes

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Default
2+
* text=auto eol=lf
3+
4+
# Binary files
5+
*.png binary
6+
*.gif binary
7+
*.jpg binary
8+
*.db binary
9+
*.jar binary
10+
*.ico binary
11+
.gitkeep binary
12+
*.pdf binary
13+
*.zip binary
14+
15+
# Fonts
16+
*.eot binary
17+
*.otf binary
18+
*.svg binary
19+
*.ttf binary
20+
*.woff binary
21+
*.woff2 binary
22+
23+
# Media
24+
*.mp4 binary
25+
26+
# Translations
27+
*.po binary
28+
*.mo binary
29+
*.pot binary

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.idea/
2+
/vendor/
3+
/composer.lock
4+
/.php_cs.cache

.php_cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->exclude('vendor')
5+
->in(__DIR__);
6+
7+
return PhpCsFixer\Config::create()
8+
->setRules(
9+
[
10+
'@Symfony' => true
11+
]
12+
)
13+
->setFinder($finder);

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (C) 2015 Maksim Kotlyar
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Setefi Payum gateway
2+
3+
TODO doc.

composer.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "webburza/payum-setefi",
3+
"type": "project",
4+
"description": "Setefi Payum gateway",
5+
"keywords": [
6+
"payment",
7+
"payum",
8+
"setefi",
9+
"monetaonline"
10+
],
11+
"homepage": "https://github.com/webburza/payum-setefi",
12+
"license": "MIT",
13+
"authors": [
14+
{
15+
"name": "Dalibor Karlović",
16+
"email": "dado@burza.hr"
17+
},
18+
{
19+
"name": "Kotlyar Maksim",
20+
"email": "kotlyar.maksim@gmail.com"
21+
},
22+
{
23+
"name": "Payum project",
24+
"homepage": "http://payum.org/"
25+
},
26+
{
27+
"name": "Community contributions",
28+
"homepage": "https://github.com/Payum/AuthorizeNetAim/contributors"
29+
}
30+
],
31+
"require": {
32+
"payum/core": "^1.3"
33+
},
34+
"require-dev": {
35+
"php-http/guzzle6-adapter": "^1.0",
36+
"friendsofphp/php-cs-fixer": "^2.0"
37+
},
38+
"autoload": {
39+
"psr-4": {
40+
"Webburza\\Payum\\": "src/"
41+
}
42+
}
43+
}

src/Action/AuthorizeAction.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace Webburza\Payum\Setefi\Action;
4+
5+
use Payum\Core\Action\ActionInterface;
6+
use Payum\Core\ApiAwareInterface;
7+
use Payum\Core\ApiAwareTrait;
8+
use Payum\Core\Bridge\Spl\ArrayObject;
9+
use Payum\Core\Exception\RequestNotSupportedException;
10+
use Payum\Core\GatewayAwareInterface;
11+
use Payum\Core\GatewayAwareTrait;
12+
use Payum\Core\Reply\HttpResponse;
13+
use Payum\Core\Request\Authorize;
14+
use Payum\Core\Request\GetHttpRequest;
15+
use Webburza\Payum\Setefi\Api;
16+
17+
/**
18+
* Class AuthorizeAction.
19+
*
20+
* @property Api $api
21+
*/
22+
class AuthorizeAction implements ActionInterface, GatewayAwareInterface, ApiAwareInterface
23+
{
24+
use GatewayAwareTrait;
25+
use ApiAwareTrait;
26+
27+
/**
28+
* Class constructor.
29+
*/
30+
public function __construct()
31+
{
32+
$this->apiClass = Api::class;
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*
38+
* @param Authorize $request
39+
*
40+
* @throws \Payum\Core\Reply\HttpResponse
41+
* @throws \Payum\Core\Exception\LogicException
42+
* @throws \Payum\Core\Reply\ReplyInterface
43+
* @throws \Payum\Core\Exception\InvalidArgumentException
44+
*/
45+
public function execute($request)
46+
{
47+
RequestNotSupportedException::assertSupports($this, $request);
48+
49+
$details = ArrayObject::ensureArrayObject($request->getModel());
50+
$httpRequest = new GetHttpRequest();
51+
$this->gateway->execute($httpRequest);
52+
53+
$authRequest = ArrayObject::ensureArrayObject($httpRequest->request);
54+
$authRequest->validateNotEmpty(['paymentid', 'securitytoken', 'authorizationcode', 'responsecode', 'result']);
55+
56+
$details->replace($this->api->authorizeTransaction((array) $details, (array) $authRequest));
57+
58+
if ($details['authorization']) {
59+
// TODO: we can communicate back with Setefi, what can we say here? Maybe a different response URL?
60+
throw new HttpResponse('OK');
61+
}
62+
}
63+
64+
/**
65+
* {@inheritdoc}
66+
*/
67+
public function supports($request)
68+
{
69+
return
70+
$request instanceof Authorize &&
71+
$request->getModel() instanceof \ArrayAccess;
72+
}
73+
}

src/Action/CaptureAction.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace Webburza\Payum\Setefi\Action;
4+
5+
use Payum\Core\Action\ActionInterface;
6+
use Payum\Core\ApiAwareInterface;
7+
use Payum\Core\ApiAwareTrait;
8+
use Payum\Core\Bridge\Spl\ArrayObject;
9+
use Payum\Core\Exception\RequestNotSupportedException;
10+
use Payum\Core\GatewayAwareInterface;
11+
use Payum\Core\GatewayAwareTrait;
12+
use Payum\Core\Request\Authorize;
13+
use Payum\Core\Request\Capture;
14+
use Webburza\Payum\Setefi\Api;
15+
use Webburza\Payum\Setefi\Request\CreateTransaction;
16+
17+
/**
18+
* Class CaptureAction.
19+
*
20+
* @property Api $api
21+
*/
22+
class CaptureAction implements ActionInterface, ApiAwareInterface, GatewayAwareInterface
23+
{
24+
use ApiAwareTrait;
25+
use GatewayAwareTrait;
26+
27+
/**
28+
* Class constructor.
29+
*/
30+
public function __construct()
31+
{
32+
$this->apiClass = Api::class;
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*
38+
* @param Capture $request
39+
*
40+
* @throws \Payum\Core\Reply\HttpPostRedirect
41+
* @throws \Payum\Core\Reply\ReplyInterface
42+
*/
43+
public function execute($request)
44+
{
45+
RequestNotSupportedException::assertSupports($this, $request);
46+
47+
$details = ArrayObject::ensureArrayObject($request->getModel());
48+
49+
if (null === $details['payment']) {
50+
// TODO: hardcoded for now
51+
$details['language'] = Api::LANGUAGE_ITA;
52+
if (null === $details['responseToMerchantUrl'] && $request->getToken()) {
53+
// server to server sync
54+
$details['responseToMerchantUrl'] = $request->getToken()->getTargetUrl();
55+
}
56+
if (null === $details['recoveryUrl'] && $request->getToken()) {
57+
// if our server to server fails, this way we'll still try to sync
58+
// otherwise just redirect to success
59+
$details['recoveryUrl'] = $request->getToken()->getTargetUrl();
60+
}
61+
62+
// first pass
63+
// we're need to create the transaction on Setefi
64+
// and redirect the user there
65+
$this->gateway->execute(new CreateTransaction($details));
66+
} elseif (null === $details['authorization']) {
67+
// second pass
68+
// we're authorizing the transaction by a server-to-server request
69+
// this request is served to Setefi backend, NOT the returning user
70+
$this->gateway->execute(new Authorize($details));
71+
}
72+
}
73+
74+
/**
75+
* {@inheritdoc}
76+
*/
77+
public function supports($request)
78+
{
79+
return
80+
$request instanceof Capture &&
81+
$request->getModel() instanceof \ArrayAccess;
82+
}
83+
}

src/Action/ConvertPaymentAction.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace Webburza\Payum\Setefi\Action;
4+
5+
use Payum\Core\Action\ActionInterface;
6+
use Payum\Core\Bridge\Spl\ArrayObject;
7+
use Payum\Core\Exception\RequestNotSupportedException;
8+
use Payum\Core\GatewayAwareInterface;
9+
use Payum\Core\GatewayAwareTrait;
10+
use Payum\Core\Model\PaymentInterface;
11+
use Payum\Core\Request\Convert;
12+
use Payum\Core\Request\GetCurrency;
13+
14+
/**
15+
* Class ConvertPaymentAction.
16+
*/
17+
class ConvertPaymentAction implements ActionInterface, GatewayAwareInterface
18+
{
19+
use GatewayAwareTrait;
20+
21+
/**
22+
* {@inheritdoc}
23+
*
24+
* @throws \Payum\Core\Reply\ReplyInterface
25+
* @throws \Payum\Core\Exception\InvalidArgumentException
26+
*/
27+
public function execute($request)
28+
{
29+
RequestNotSupportedException::assertSupports($this, $request);
30+
31+
/** @var PaymentInterface $payment */
32+
$payment = $request->getSource();
33+
34+
$this->gateway->execute($currency = new GetCurrency($payment->getCurrencyCode()));
35+
$divisor = pow(10, $currency->exp);
36+
37+
$details = ArrayObject::ensureArrayObject($payment->getDetails());
38+
$details['currencyCode'] = $payment->getCurrencyCode();
39+
$details['amount'] = $payment->getTotalAmount() / $divisor;
40+
$details['description'] = $payment->getDescription();
41+
$details['merchantOrderId'] = $payment->getNumber();
42+
43+
$request->setResult((array) $details);
44+
}
45+
46+
/**
47+
* {@inheritdoc}
48+
*/
49+
public function supports($request)
50+
{
51+
return
52+
$request instanceof Convert &&
53+
$request->getSource() instanceof PaymentInterface &&
54+
$request->getTo() === 'array';
55+
}
56+
}

0 commit comments

Comments
 (0)