-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from webmacaj/master
widget purchase
- Loading branch information
Showing
3 changed files
with
147 additions
and
0 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,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'; | ||
} | ||
} |
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,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' | ||
]; | ||
} | ||
} |
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,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); | ||
|
||
} | ||
} |