<?php

/**
 * Component for working with mPDF class.
 * mPDF has to be in the vendors directory.
 */
class EwayComponent extends Component {

    public function payment($payment_data) {
        App::import('Vendor', 'eway/include_eway');

        $apiKey='60CF3Ce97nRS1Z1Wp5m9kMmzHHEh8Rkuj31QCtVxjPWGYA9FymyqsK0Enm1P6mHJf0THbR';
              $apiPassword='API-P4ss';
             $apiEndpoint = \Eway\Rapid\Client::MODE_SANDBOX;
             $client = \Eway\Rapid::createClient($apiKey, $apiPassword, $apiEndpoint);
             $client->setVersion(40);

               $transaction = [
                'Customer' => [
                    'CardDetails' => [
                        'Name' => $payment_data['CustomerCredit']['cardname'],
                        'Number' => $payment_data['CustomerCredit']['creditcardno'],
                        'ExpiryMonth' => $payment_data['CustomerCredit']['creditcardexpirymonth'],
                        'ExpiryYear' => $payment_data['CustomerCredit']['creditcardexpiryyear'],
                        'CVN' => $payment_data['CustomerCredit']['creditcardccvno'],
                    ]
                ],
                'Payment' => [
                    'TotalAmount' => $payment_data['CustomerCredit']['amount'],
                ],
                'TransactionType' => \Eway\Rapid\Enum\TransactionType::PURCHASE,
            ];

            $response = $client->createTransaction(\Eway\Rapid\Enum\ApiMethod::DIRECT, $transaction);

            if ($response->TransactionStatus) {
                $rsponseID=$response->TransactionID;
            }
            else{
                $rsponseID=0;
                
            }
            return $rsponseID;
}

        // Display a confirmation message on the screen
    

}
