-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
130efd6
commit 07ae2e7
Showing
5 changed files
with
122 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vendor | ||
bin | ||
/.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
namespace PTS\Paysera; | ||
|
||
use Http\Message\MessageFactory; | ||
use function League\Uri\create; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use Payum\Core\Exception\Http\HttpException; | ||
use Payum\Core\HttpClientInterface; | ||
use Payum\Core\Reply\HttpPostRedirect; | ||
use Payum\Core\Reply\HttpResponse; | ||
use Payum\Core\Request\GetHttpRequest; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use WebToPay; | ||
|
||
class MockedApi | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $options = []; | ||
|
||
/** | ||
* Api constructor. | ||
* @param array $options | ||
*/ | ||
public function __construct(array $options) | ||
{ | ||
$options = ArrayObject::ensureArrayObject($options); | ||
$options->defaults($this->options); | ||
|
||
$this->options = $options; | ||
} | ||
|
||
public function doPayment(array $fields) | ||
{ | ||
$fields['projectid'] = $this->options['projectid']; | ||
$fields['sign_password'] = $this->options['sign_password']; | ||
$this->options['test'] ? $fields['test'] = 1 : $fields['test'] = 0; | ||
$authorizeTokenUrl = $this->getApiEndpoint(); | ||
$data = WebToPay::buildRequest($fields); | ||
throw new HttpPostRedirect($authorizeTokenUrl, $data); | ||
} | ||
|
||
public function doNotify(array $fields) | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getApiEndpoint() | ||
{ | ||
return WebToPay::PAY_URL; | ||
} | ||
|
||
public function getApiOptions() | ||
{ | ||
return $this->options; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace PTS\Paysera; | ||
|
||
use PTS\Paysera\Action\AuthorizeAction; | ||
use PTS\Paysera\Action\CancelAction; | ||
use PTS\Paysera\Action\ConvertPaymentAction; | ||
use PTS\Paysera\Action\CaptureAction; | ||
use PTS\Paysera\Action\NotifyAction; | ||
use PTS\Paysera\Action\RefundAction; | ||
use PTS\Paysera\Action\StatusAction; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use Payum\Core\GatewayFactory; | ||
|
||
class MockedPayseraGatewayFactory extends GatewayFactory | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function populateConfig(ArrayObject $config) | ||
{ | ||
$config->defaults([ | ||
'payum.factory_name' => 'paysera', | ||
'payum.factory_title' => 'paysera', | ||
'payum.action.capture' => new CaptureAction($mocked = true), | ||
'payum.action.authorize' => new AuthorizeAction(), | ||
'payum.action.refund' => new RefundAction(), | ||
'payum.action.cancel' => new CancelAction(), | ||
'payum.action.notify' => new NotifyAction($mocked = true), | ||
'payum.action.status' => new StatusAction(), | ||
'payum.action.convert_payment' => new ConvertPaymentAction(), | ||
]); | ||
|
||
if (false == $config['payum.api']) { | ||
$config['payum.default_options'] = array( | ||
'projectid' => '', | ||
'sign_password' => '', | ||
'test' => true, | ||
); | ||
$config->defaults($config['payum.default_options']); | ||
$config['payum.required_options'] = [ | ||
'projectid', 'sign_password' | ||
]; | ||
|
||
$config['payum.api'] = function (ArrayObject $config) { | ||
$config->validateNotEmpty($config['payum.required_options']); | ||
|
||
return new MockedApi((array)$config); | ||
}; | ||
} | ||
} | ||
} |