Merge pull request #4855 from beganovich/v5-0902-custom-driver-variables

(v5) Allow variables in the custom payment driver
This commit is contained in:
David Bomba 2021-02-15 21:32:00 +11:00 committed by GitHub
commit 1feba49670
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,13 +14,18 @@ namespace App\PaymentDrivers;
use App\Models\ClientGatewayToken; use App\Models\ClientGatewayToken;
use App\Models\GatewayType; use App\Models\GatewayType;
use App\Models\Invoice;
use App\Models\Payment; use App\Models\Payment;
use App\Utils\HtmlEngine;
use App\Utils\Traits\MakesHash;
/** /**
* Class CustomPaymentDriver. * Class CustomPaymentDriver.
*/ */
class CustomPaymentDriver extends BaseDriver class CustomPaymentDriver extends BaseDriver
{ {
use MakesHash;
public $token_billing = false; public $token_billing = false;
public $can_authorise_credit_card = false; public $can_authorise_credit_card = false;
@ -52,8 +57,14 @@ class CustomPaymentDriver extends BaseDriver
*/ */
public function processPaymentView($data) public function processPaymentView($data)
{ {
$invitation = Invoice::findOrFail(
$this->decodePrimaryKey($data['invoices']['0']['invoice_id'])
)->invitations->first();
$variables = (new HtmlEngine($invitation))->generateLabelsAndValues();
$data['title'] = $this->company_gateway->getConfigField('name'); $data['title'] = $this->company_gateway->getConfigField('name');
$data['instructions'] = $this->company_gateway->getConfigField('text'); $data['instructions'] = strtr($this->company_gateway->getConfigField('text'), $variables['values']);
$this->payment_hash->data = array_merge((array) $this->payment_hash->data, $data); $this->payment_hash->data = array_merge((array) $this->payment_hash->data, $data);
$this->payment_hash->save(); $this->payment_hash->save();