Skip to content

Commit

Permalink
Merge pull request #3 from webmacaj/master
Browse files Browse the repository at this point in the history
widget purchase
  • Loading branch information
segy authored Apr 20, 2021
2 parents 06f1b12 + 572dd33 commit 7a2521f
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/Message/WidgetPurchaseRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php


namespace Omnipay\Besteron\Message;


use Omnipay\Common\Message\AbstractResponse;

class WidgetPurchaseRequest extends PurchaseRequest
{
/**
* {@inheritdoc}
*/
public function getData()
{
$data = parent::getData();
unset($data['type']);

$data['language'] = $this->getLang();
$data['paymentmethod'] = 'CARDANDBUTTON';

return $data;
}

/**
* Get hash for request
*
* @return string
*/
public function getHash()
{
return $this->createHash($this->getCid() . 'CARDANDBUTTON' . $this->getAmount() . $this->getCurrencyNumeric() . $this->getTransactionId() . $this->getReturnUrl());
}

/**
* {@inheritdoc}
*/
public function sendData($data)
{
return $this->response = new WidgetPurchaseResponse($this, $data);
}

/**
* Get endpoint
*
* @return string
*/
public function getEndpoint()
{
return $this->getTest() ? 'https://client.besteron.com/inline/besteronInlineVirtual.js' : 'https://client.besteron.com/inline/besteronInline.js';
}
}
65 changes: 65 additions & 0 deletions src/Message/WidgetPurchaseResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
namespace Omnipay\Besteron\Message;

/**
* Besteron Widget Purchase Response
*/
class WidgetPurchaseResponse extends PurchaseResponse
{
/**
* Get required html.
*
* @return string
*/
public function getHtml()
{
return '<div class="shop-iframe" id="shop-iframe"></div>';
}

/**
* Get inline script.
*
* @return string
*/
public function getScript()
{
$data = \json_encode($this->getData());

return "
window.Besteron || (function (d) {
var s, c, o = besteron = function () { o._.push(arguments) }; o._ = [];
s = d.getElementsByTagName('script')[0]; c = d.createElement('script');
c.type = 'text/javascript'; c.charset = 'utf-8'; c.async = false;
c.src = '" . $this->request->getEndpoint() . "'; s.parentNode.insertBefore(c, s);
})(document);
window.addEventListener('load', function() {
var paymentData = " . $data . ";
var _elm = document.getElementById('shop-iframe');
window.Besteron.show(document, _elm, paymentData);
})
";
}

/**
* Get external js scripts.
*
* @return string[]|array
*/
public function getExternalScripts()
{
return [];
}

/**
* Get external css links.
*
* @return string[]
*/
public function getExternalLinks()
{
return [
'https://client.besteron.com/inline/css/widget.css'
];
}
}
30 changes: 30 additions & 0 deletions src/WidgetGateway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
namespace Omnipay\Besteron;

/**
* Besteron Widget Gateway
*/
class WidgetGateway extends Gateway
{
/**
* Create a purchase request
*
* @param array $parameters
* @return \Omnipay\Besteron\Message\BankPayPurchaseRequest
*/
public function purchase(array $parameters = [])
{
return $this->createRequest('\Omnipay\Besteron\Message\WidgetPurchaseRequest', $parameters);
}

/**
* Create a complete purchase request
*
* @param array $parameters
*/
public function completePurchase(array $parameters = [])
{
return $this->createRequest('\Omnipay\Besteron\Message\CompletePurchaseRequest', $parameters);

}
}

0 comments on commit 7a2521f

Please sign in to comment.