<commit_before><?php

/*
 * This file is part of the Omnipay package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Omnipay\NetBanx\Message;

use Omnipay\Common\CreditCard;

/**
 * NetBanx Authorize Request
 */
class AuthorizeRequest extends AbstractRequest
{
    const MODE_AUTH = 'ccAuthorize';
    const MODE_STORED_DATA_AUTH = 'ccStoredDataAuthorize';

    /**
     * Method
     *
     * @var string
     */
    protected $txnMode;

    /**
     * Get data
     *
     * @return array
     */
    public function getData()
    {
        if ($this->getTransactionReference()) {
            $this->txnMode = $this->getStoredDataMode();
            $this->validate('amount');
        } else {
            $this->txnMode = $this->getBasicMode();
            $this->validate('amount', 'card');
            $this->getCard()->validate();
        }

        $data = $this->getBaseData();
        $data['txnRequest'] = $this->getXmlString();

        return $data;
    }

    /**
     * Get XML string
     *
     * @return string
     */
    protected function getXmlString()
    {
        if ($this->getTransactionReference()) {
            $xmlRoot = 'ccStoredDataRequestV1';
        } else {
            $xmlRoot = 'ccAuthRequestV1';
        }

        $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
                <{$xmlRoot}
                    xmlns=\"http://www.optimalpayments.com/creditcard/xmlschema/v1\"
                    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
                    xsi:schemaLocation=\"http://www.optimalpayments.com/creditcard/xmlschema/v1\" />";

        $sxml = new \SimpleXMLElement($xml);

        $merchantAccount = $sxml->addChild('merchantAccount');

        $merchantAccount->addChild('accountNum', $this->getAccountNumber());
        $merchantAccount->addChild('storeID', $this->getStoreId());
        $merchantAccount->addChild('storePwd', $this->getStorePassword());

        $sxml->addChild('merchantRefNum', $this->getCustomerId() ?: 'ref-num - ' . time());

        if ($this->getTransactionReference()) {
            $sxml->addChild('confirmationNumber', $this->getTransactionReference());
            $sxml->addChild('amount', $this->getAmountDecimal());
        } else {
            /** @var $card CreditCard */
            $card = $this->getCard();

            $sxml->addChild('amount', $this->getAmountDecimal());

            $cardChild = $sxml->addChild('card');

            $cardChild->addChild('cardNum', $card->getNumber());

            $cardExpiry = $cardChild->addChild('cardExpiry');
            $cardExpiry->addChild('month', $card->getExpiryDate('m'));
            $cardExpiry->addChild('year', $card->getExpiryDate('Y'));

            $cardChild->addChild('cardType', $this->translateCardType($card->getBrand()));
            $cardChild->addChild('cvdIndicator', '1');
            $cardChild->addChild('cvd', $card->getCvv());

            $billingDetails = $sxml->addChild('billingDetails');

            $billingDetails->addChild('cardPayMethod', 'WEB');
            $billingDetails->addChild('firstName', $card->getBillingFirstName());
            $billingDetails->addChild('lastName', $card->getBillingLastName());
            $billingDetails->addChild('street', $card->getBillingAddress1());
            $billingDetails->addChild('street2', $card->getBillingAddress2());
            $billingDetails->addChild('city', $card->getBillingCity());
            $billingDetails->addChild('state', $card->getBillingState());
            $billingDetails->addChild('country', $card->getBillingCountry());
            $billingDetails->addChild('zip', $card->getBillingPostcode());<commit_msg>check for cardReference as well as transactionReference<commit_after><?php

/*
 * This file is part of the Omnipay package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Omnipay\NetBanx\Message;

use Omnipay\Common\CreditCard;

/**
 * NetBanx Authorize Request
 */
class AuthorizeRequest extends AbstractRequest
{
    const MODE_AUTH = 'ccAuthorize';
    const MODE_STORED_DATA_AUTH = 'ccStoredDataAuthorize';

    /**
     * Method
     *
     * @var string
     */
    protected $txnMode;

    /**
     * Get data
     *
     * @return array
     */
    public function getData()
    {
        if ($this->getTransactionReference() || $this->getCardReference()) {
            $this->txnMode = $this->getStoredDataMode();
            $this->validate('amount');
        } else {
            $this->txnMode = $this->getBasicMode();
            $this->validate('amount', 'card');
            $this->getCard()->validate();
        }

        $data = $this->getBaseData();
        $data['txnRequest'] = $this->getXmlString();

        return $data;
    }

    /**
     * Get XML string
     *
     * @return string
     */
    protected function getXmlString()
    {
        if ($this->getTransactionReference() || $this->getCardReference()) {
            $xmlRoot = 'ccStoredDataRequestV1';
        } else {
            $xmlRoot = 'ccAuthRequestV1';
        }

        $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
                <{$xmlRoot}
                    xmlns=\"http://www.optimalpayments.com/creditcard/xmlschema/v1\"
                    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
                    xsi:schemaLocation=\"http://www.optimalpayments.com/creditcard/xmlschema/v1\" />";

        $sxml = new \SimpleXMLElement($xml);

        $merchantAccount = $sxml->addChild('merchantAccount');

        $merchantAccount->addChild('accountNum', $this->getAccountNumber());
        $merchantAccount->addChild('storeID', $this->getStoreId());
        $merchantAccount->addChild('storePwd', $this->getStorePassword());

        $sxml->addChild('merchantRefNum', $this->getCustomerId() ?: 'ref-num - ' . time());

        if ($this->getTransactionReference() || $this->getCardReference()) {
            $sxml->addChild('confirmationNumber', $this->getTransactionReference() ?: $this->getCardReference());
            $sxml->addChild('amount', $this->getAmountDecimal());
        } else {
            /** @var $card CreditCard */
            $card = $this->getCard();

            $sxml->addChild('amount', $this->getAmountDecimal());

            $cardChild = $sxml->addChild('card');

            $cardChild->addChild('cardNum', $card->getNumber());

            $cardExpiry = $cardChild->addChild('cardExpiry');
            $cardExpiry->addChild('month', $card->getExpiryDate('m'));
            $cardExpiry->addChild('year', $card->getExpiryDate('Y'));

            $cardChild->addChild('cardType', $this->translateCardType($card->getBrand()));
            $cardChild->addChild('cvdIndicator', '1');
            $cardChild->addChild('cvd', $card->getCvv());

            $billingDetails = $sxml->addChild('billingDetails');

            $billingDetails->addChild('cardPayMethod', 'WEB');
            $billingDetails->addChild('firstName', $card->getBillingFirstName());
            $billingDetails->addChild('lastName', $card->getBillingLastName());
            $billingDetails->addChild('street', $card->getBillingAddress1());
            $billingDetails->addChild('street2', $card->getBillingAddress2());
            $billingDetails->addChild('city', $card->getBillingCity());
            $billingDetails->addChild('state', $card->getBillingState());
            $billingDetails->addChild('country', $card->getBillingCountry());
            $billingDetails->addChild('zip', $card->getBillingPostcode());
{'fraction_non_alphanumeric': 0.17041053446940357, 'fraction_numerical': 0.004131164471985541, 'mean_word_length': 2.625175479644361, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 2, '>': 139, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 36}, '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': '4932466', 'n_tokens_mistral': 2308, 'n_tokens_neox': 2245, 'n_words': 339}