<commit_before><?php

namespace AvoRed\Ecommerce\Payment\Stripe;

use Stripe\Charge;
use Stripe\Stripe;
use AvoRed\Ecommerce\Models\Database\Configuration;
use AvoRed\Framework\Payment\Payment as PaymentEcommerce;
use AvoRed\Framework\Payment\Contracts\Payment as PaymentContracts;

class Payment extends PaymentEcommerce implements PaymentContracts
{
    const CONFIG_KEY                = 'payment_stripe_enabled';

    const CONFIG_PUBLISHABLE_KEY    = 'payment_stripe_publishable_key';

    const CONFIG_SECRET_KEY         = 'payment_stripe_secret_key';
    /**
     * Payment Option Identifier.
     *
     * @var string
     */
    protected $identifier = 'stripe';

    /**
     * Payment Option Name.
     *
     * @var string
     */
    protected $name = 'Stripe';

    /**
     * Payment Option View.
     *
     * @var string
     */
    protected $view = 'avored-ecommerce::payment.stripe.index';

    public function enable()
    {
        $model = new Configuration();
        $isEnabled = $model->getConfiguration(self::CONFIG_KEY);
        if (null === $isEnabled || false == $isEnabled) {
            return false;
        }

        return true;
    }

    public function identifier()
    {
        return $this->identifier;
    }

    public function name()
    {
        return $this->name;
    }

    public function view()
    {
        return $this->view;
    }

    public function with()
    {
        $token = Configuration::getConfiguration(self::CONFIG_PUBLISHABLE_KEY);
        $data = ['token' => $token];

        return $data;
    }

    /*
     * Nothing to do
     *
     */
    public function process($orderData, $cartProducts, $request)
    {
        $subTotal = 0;
        $taxTotal = 0;

        foreach ($cartProducts as $product) {
            $subTotal += $product['price'] * $product['qty'];
            $taxTotal += $product['tax_amount'] * $product['qty'];
        }

        $total = (round($subTotal, 2) + round($taxTotal, 2)) * 100;

        $totalCents = (int) $total;
        $apiKey = Configuration::getConfiguration(self::CONFIG_SECRET_KEY);

        Stripe::setApiKey($apiKey);

        $response = Charge::create([
            'amount' => $totalCents,
            'currency' => 'nzd',
            'source' => $request->get('stripeToken'), // obtained with Stripe.js
            'description' => 'AvoRed E commerce',
        ]);

        return $response;
    }
}
<commit_msg>fixed issue # 144 Configuration non-static methods<commit_after><?php

namespace AvoRed\Ecommerce\Payment\Stripe;

use Stripe\Charge;
use Stripe\Stripe;
use AvoRed\Framework\Models\Database\Configuration;
use AvoRed\Framework\Payment\Payment as PaymentEcommerce;
use AvoRed\Framework\Payment\Contracts\Payment as PaymentContracts;

class Payment extends PaymentEcommerce implements PaymentContracts
{
    const CONFIG_KEY                = 'payment_stripe_enabled';

    const CONFIG_PUBLISHABLE_KEY    = 'payment_stripe_publishable_key';

    const CONFIG_SECRET_KEY         = 'payment_stripe_secret_key';
    /**
     * Payment Option Identifier.
     *
     * @var string
     */
    protected $identifier = 'stripe';

    /**
     * Payment Option Name.
     *
     * @var string
     */
    protected $name = 'Stripe';

    /**
     * Payment Option View.
     *
     * @var string
     */
    protected $view = 'avored-ecommerce::payment.stripe.index';

    public function enable()
    {
        $model = new Configuration();
        $isEnabled = $model->getConfiguration(self::CONFIG_KEY);
        if (null === $isEnabled || false == $isEnabled) {
            return false;
        }

        return true;
    }

    public function identifier()
    {
        return $this->identifier;
    }

    public function name()
    {
        return $this->name;
    }

    public function view()
    {
        return $this->view;
    }

    public function with()
    {
        $token = Configuration::getConfiguration(self::CONFIG_PUBLISHABLE_KEY);
        $data = ['token' => $token];

        return $data;
    }

    /*
     * Nothing to do
     *
     */
    public function process($orderData, $cartProducts, $request)
    {
        $subTotal = 0;
        $taxTotal = 0;

        foreach ($cartProducts as $product) {
            $subTotal += $product['price'] * $product['qty'];
            $taxTotal += $product['tax_amount'] * $product['qty'];
        }

        $total = (round($subTotal, 2) + round($taxTotal, 2)) * 100;

        $totalCents = (int) $total;
        $apiKey = Configuration::getConfiguration(self::CONFIG_SECRET_KEY);

        Stripe::setApiKey($apiKey);

        $response = Charge::create([
            'amount' => $totalCents,
            'currency' => 'nzd',
            'source' => $request->get('stripeToken'), // obtained with Stripe.js
            'description' => 'AvoRed E commerce',
        ]);

        return $response;
    }
}

{'fraction_non_alphanumeric': 0.12824178068205022, 'fraction_numerical': 0.0034715131713293854, 'mean_word_length': 2.2480106100795756, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '1689014', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1425, 'n_words': 303}