<commit_before><?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

namespace Larium\Pay\Gateway;

use Larium\Pay\Transaction\Void;
use Larium\Pay\Client\RestClient;
use Larium\Pay\Transaction\Refund;
use Larium\Pay\Transaction\Capture;
use Larium\Pay\Transaction\Purchase;
use Larium\Pay\Transaction\Authorize;
use Larium\Pay\Transaction\Transaction;
use Larium\Pay\Exception\NotImplementedException;

abstract class Gateway
{
    protected $options;

    public function __construct(array $options = [])
    {
        $this->options = $options;
    }

    public function execute(Transaction $transaction)
    {
        $transaction->commit();

        switch (true) {
            case $transaction instanceof Purchase:
                return $this->purchase($transaction);
            case $transaction instanceof Authorize:
                return $this->authorize($transaction);
            case $transaction instanceof Capture:
                return $this->capture($transaction);
            case $transaction instanceof Refund:
                return $this->refund($transaction);
            case $transaction instanceof Void:
                return $this->void($transaction);
            default:
                throw new \RuntimeException(
                    sprintf('Invalid transaction type `%s`', get_class($transaction))
                );
        }
    }

    protected function purchase(Purchase $transaction)
    {
        throw new NotImplementedException(
            sprintf('Transaction `%s` in not implemented by `%s`', __FUNCTION__, get_class($this))
        );
    }

    protected function authorize(Authorize $transaction)
    {
        throw new NotImplementedException(
            sprintf('Transaction `%s` in not implemented by `%s`', __FUNCTION__, get_class($this))
        );
    }

    protected function capture(Capture $transaction)
    {
        throw new NotImplementedException(
            sprintf('Transaction `%s` in not implemented by `%s`', __FUNCTION__, get_class($this))
        );
    }

    protected function refund(Refund $transaction)
    {
        throw new NotImplementedException(
            sprintf('Transaction `%s` in not implemented by `%s`', __FUNCTION__, get_class($this))
        );
    }

    protected function void(Void $transaction)
    {
        throw new NotImplementedException(
            sprintf('Transaction `%s` in not implemented by `%s`', __FUNCTION__, get_class($this))<commit_msg>add callback to transform response from gateway.<commit_after><?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

namespace Larium\Pay\Gateway;

use Larium\Pay\Transaction\Void;
use Larium\Pay\Client\RestClient;
use Larium\Pay\Transaction\Refund;
use Larium\Pay\Transaction\Capture;
use Larium\Pay\Transaction\Purchase;
use Larium\Pay\Transaction\Authorize;
use Larium\Pay\Transaction\Transaction;
use Larium\Pay\Exception\NotImplementedException;

abstract class Gateway
{
    protected $options;

    public function __construct(array $options = [])
    {
        $this->options = $options;
    }

    public function execute(Transaction $transaction, callable $callback = null)
    {
        $transaction->commit();

        switch (true) {
            case $transaction instanceof Purchase:
                return $this->purchase($transaction, $callback);
            case $transaction instanceof Authorize:
                return $this->authorize($transaction, $callback);
            case $transaction instanceof Capture:
                return $this->capture($transaction, $callback);
            case $transaction instanceof Refund:
                return $this->refund($transaction, $callback);
            case $transaction instanceof Void:
                return $this->void($transaction, $callback);
            default:
                throw new \RuntimeException(
                    sprintf('Invalid transaction type `%s`', get_class($transaction))
                );
        }
    }

    protected function purchase(Purchase $transaction, callable $callback = null)
    {
        throw new NotImplementedException(
            sprintf('Transaction `%s` in not implemented by `%s`', __FUNCTION__, get_class($this))
        );
    }

    protected function authorize(Authorize $transaction, callable $callback = null)
    {
        throw new NotImplementedException(
            sprintf('Transaction `%s` in not implemented by `%s`', __FUNCTION__, get_class($this))
        );
    }

    protected function capture(Capture $transaction, callable $callback = null)
    {
        throw new NotImplementedException(
            sprintf('Transaction `%s` in not implemented by `%s`', __FUNCTION__, get_class($this))
        );
    }

    protected function refund(Refund $transaction, callable $callback = null)
    {
        throw new NotImplementedException(
            sprintf('Transaction `%s` in not implemented by `%s`', __FUNCTION__, get_class($this))
        );
    }

    protected function void(Void $transaction, callable $callback = null)
    {
        throw new NotImplementedException(
            sprintf('Transaction `%s` in not implemented by `%s`', __FUNCTION__, get_class($this))
{'fraction_non_alphanumeric': 0.10318985395849346, 'fraction_numerical': 0.0011529592621060721, 'mean_word_length': 2.688873139617293, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3675807', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1313, 'n_words': 352}