1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Payments\Controllers\Traits\PurchaseController; |
4
|
|
|
|
5
|
|
|
use ByTIC\Common\Records\Record; |
6
|
|
|
use ByTIC\FacebookPixel\FacebookPixel; |
7
|
|
|
use ByTIC\Omnipay\Common\Message\Traits\RedirectHtmlTrait; |
8
|
|
|
use ByTIC\Payments\Models\Purchase\Traits\IsPurchasableModelTrait; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Trait PurchaseRedirectActionsTrait |
12
|
|
|
* @package ByTIC\Payments\Controllers\Traits\PurchaseController |
13
|
|
|
*/ |
14
|
|
|
trait PurchaseRedirectActionsTrait |
15
|
|
|
{ |
16
|
|
|
public function redirectToPayment() |
17
|
|
|
{ |
18
|
|
|
$model = $this->getModelFromRequest(); |
|
|
|
|
19
|
|
|
$request = $model->getPurchaseRequest(); |
20
|
|
|
/** @var RedirectHtmlTrait $response */ |
21
|
|
|
$response = $request->send(); |
22
|
|
|
$this->redirectToPaymentPrepareResponse($response, $model); |
23
|
|
|
$response->getRedirectResponse()->send(); |
24
|
|
|
die(); |
|
|
|
|
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param RedirectHtmlTrait $response |
29
|
|
|
* @param Record|IsPurchasableModelTrait $model |
30
|
|
|
*/ |
31
|
|
|
protected function redirectToPaymentPrepareResponse($response, $model) |
32
|
|
|
{ |
33
|
|
|
$response->getView()->set('subtitle', $model->getPurchaseName()); |
34
|
|
|
$response->getView()->set('item', $model); |
35
|
|
|
$response->getView()->set('response', $model); |
36
|
|
|
|
37
|
|
|
if (method_exists($this, 'getFacebookPixelToPaymentResponse')) { |
38
|
|
|
/** @var FacebookPixel $facebookPixel */ |
39
|
|
|
$facebookPixel = $this->getFacebookPixelToPaymentResponse($model); |
40
|
|
|
$response->getView()->append('footer_body', $facebookPixel->render()); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|