Skip to content

Commit

Permalink
feat: payment handler, simple implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Klimchuk committed Jul 23, 2021
1 parent 56b447a commit a9045db
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
12 changes: 3 additions & 9 deletions core/mspklarna/KlarnaGatewayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,22 @@
interface KlarnaGatewayInterface
{
public const AREA_CREDENTIALS = 'credentials';
public const OPTION_CASH_REGISTER_NUMBER = 'cash_register_number';
public const OPTION_CASH_PASSWORD = 'cash_password';
public const OPTION_USERNAME = 'username';
public const OPTION_PASSWORD = 'password';

public const AREA_GATEWAYS = 'gateways';
public const OPTION_GATEWAY_REGION = 'region';
public const OPTION_GATEWAY_URL = 'gateway_url';
public const OPTION_GATEWAY_URL_TEST = 'gateway_url_test';
public const OPTION_DEVELOPER_MODE = 'developer_mode';

public const AREA_RECEIPT = 'receipt';
public const OPTION_TITLE_TEXT = 'title_text';
public const OPTION_HEADER_TEXT = 'receipt_header_text';
public const OPTION_FOOTER_TEXT = 'receipt_footer_text';
public const OPTION_PRINT_CASH_REGISTER_NUMBER = 'print_crn';

public const AREA_STATUSES = 'statuses';
public const OPTION_SUCCESS_STATUS = 'success_status';
public const OPTION_FAILURE_STATUS = 'failure_status';

public const AREA_PAGES = 'pages';
public const OPTION_SUCCESS_PAGE = 'success_page';
public const OPTION_FAILURE_PAGE = 'failure_page';
public const OPTION_UNPAID_PAGE = 'unpaid_page';

public function getPaymentLink(msOrder $order): string;

Expand Down
54 changes: 47 additions & 7 deletions core/mspklarna/KlarnaHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class KlarnaHandler extends ConfigurablePaymentHandler implements KlarnaGatewayI
{
public static function getPrefix(): string
{
return 'oplati';
return 'klarna';
}

/**
Expand All @@ -48,11 +48,51 @@ public function getPaymentLink(msOrder $order): string

$this->config = $this->getProperties($payment);

return $this->modx->makeUrl(
$this->config[self::OPTION_UNPAID_PAGE],
$this->modx->context->get('key'),
modX::toQueryString(['msorder' => $order->get('id')]),
'full'
);
/** @var KlarnaService $service */
$service = $this->modx->getService('klarna', KlarnaService::class);

$res = $service->requestPayment($order);

$arr = $this->modx->fromJSON($res);

echo $arr['session_id'];

$answ = $service->requestRedirect($arr['session_id']);
$aw = $answ->getBody()->getContents();

print_r($aw);

die();

// - get gateway links
//

// {
// "purchase_country": "GB",
// "purchase_currency": "GBP",
// "locale": "en-GB",
// "order_amount": 10,
// "order_tax_amount": 0,
// "order_lines": [{
// "type": "physical",
// "reference": "19-402",
// "name": "Battery Power Pack",
// "quantity": 1,
// "unit_price": 10,
// "tax_rate": 0,
// "total_amount": 10,
// "total_discount_amount": 0,
// "total_tax_amount": 0,
// "image_url": "https://www.exampleobjects.com/logo.png",
// "product_url": "https://www.estore.com/products/f2a8d7e34"
// }]
//}
return '';
// return $this->modx->makeUrl(
// $this->config[self::OPTION_UNPAID_PAGE],
// $this->modx->context->get('key'),
// modX::toQueryString(['msorder' => $order->get('id')]),
// 'full'
// );
}
}

0 comments on commit a9045db

Please sign in to comment.