PHP code example of wmd / craft-bank-transfer-payment-codes

1. Go to this page and download the library: Download wmd/craft-bank-transfer-payment-codes library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wmd / craft-bank-transfer-payment-codes example snippets


use wmd\banktransferpaymentcodes\Plugin as Btpc;

$result = Btpc::getInstance()->payments->markPaid('HR00 2026001', 24.60, 'erp');
if ($result->ok) {
    // $result->status === 'paid'
} else {
    // 'underpaid', 'overpaid', 'already_paid', 'not_found', 'wrong_gateway',
    // 'no_transaction', 'capture_failed' or 'locked'; $result->message explains it
}

use wmd\banktransferpaymentcodes\events\RegisterComponentsEvent;
use wmd\banktransferpaymentcodes\formats\Formats;
use yii\base\Event;

Event::on(Formats::class, Formats::EVENT_REGISTER_FORMATS, function(RegisterComponentsEvent $e) {
    $e->components['spayd'] = new MySpaydFormat(); // Czech SPAYD, for example
});

use wmd\banktransferpaymentcodes\events\RegisterComponentsEvent;
use wmd\banktransferpaymentcodes\references\ReferenceSchemes;
use yii\base\Event;

Event::on(ReferenceSchemes::class, ReferenceSchemes::EVENT_REGISTER_REFERENCE_SCHEMES, function(RegisterComponentsEvent $e) {
    $e->components['pl'] = new MyPolishReferenceScheme();
});

use wmd\banktransferpaymentcodes\events\MarkPaidEvent;
use wmd\banktransferpaymentcodes\services\Payments;
use yii\base\Event;

Event::on(Payments::class, Payments::EVENT_AFTER_MARK_PAID, function(MarkPaidEvent $e) {
    if ($e->result->ok && $e->source === 'camt') {
        // tell the ERP the invoice is settled
    }
});
twig
{% set codes = craft.btpc.codes(order) %}
{% set details = craft.btpc.details(order) %}
{% for code in codes %}
  <figure>
    {{ code.svg()|raw }}
    <figcaption>{{ code.label() }}</figcaption>
  </figure>
{% endfor %}
{% if details %}
  <p>{{ details.account.holder }} · {{ details.account.iban }} · {{ details.amount }} {{ details.currency }} · {{ details.reference }}</p>
{% endif %}