public function testPayment($amount, ICreditCard $card, $details = [])
 {
     $auth = new Authorization(['merchantRefNum' => Random::generate(10, '0-9'), 'amount' => $amount, 'settleWithAuth' => true, 'card' => self::formatCreditCard($card), 'billingDetails' => $details]);
     return $this->client->cardPaymentService()->authorize($auth);
 }
<?php

require_once 'config.php';
use OptimalPayments\OptimalApiClient;
use OptimalPayments\Environment;
use OptimalPayments\CardPayments\Authorization;
if ($_POST) {
    $client = new OptimalApiClient($optimalApiKeyId, $optimalApiKeySecret, Environment::TEST, $optimalAccountNumber);
    try {
        $auth = $client->cardPaymentService()->authorize(new Authorization(array('merchantRefNum' => $_POST['merchant_ref_num'], 'amount' => $_POST['amount'] * $currencyBaseUnitsMultiplier, 'settleWithAuth' => true, 'card' => array('cardNum' => $_POST['card_number'], 'cvv' => $_POST['card_cvv'], 'cardExpiry' => array('month' => $_POST['card_exp_month'], 'year' => $_POST['card_exp_year'])), 'billingDetails' => array('street' => $_POST['street'], 'city' => $_POST['city'], 'state' => $_POST['state'], 'country' => $_POST['country'], 'zip' => $_POST['zip']))));
        die('Payment successful! ID: ' . $auth->id);
    } catch (OptimalPayments\NetbanxException $e) {
        echo '<pre>';
        var_dump($e->getMessage());
        if ($e->fieldErrors) {
            var_dump($e->fieldErrors);
        }
        if ($e->links) {
            var_dump($e->links);
        }
        echo '</pre>';
    } catch (\OptimalPayments\OptimalException $e) {
        //for debug only, these errors should be properly handled before production
        var_dump($e->getMessage());
    }
}
?>
<!DOCTYPE html>
<html>
	<head>
		<title>Optimal SDK - CardPayment Simple</title>
        die('An unknown error has occurred.');
    }
} elseif (isset($_GET['id'])) {
    $client = new OptimalApiClient($optimalApiKeyId, $optimalApiKeySecret, Environment::TEST, $optimalAccountNumber);
    try {
        session_start();
        if (!isset($_SESSION['order'])) {
            die('No pending order found');
        }
        $sessionOrder = $_SESSION['order'];
        unset($_SESSION['order']);
        session_destroy();
        if ($sessionOrder->id != $_GET['id']) {
            die('Invalid id');
        }
        $client = new OptimalApiClient($optimalApiKeyId, $optimalApiKeySecret, Environment::TEST, $optimalAccountNumber);
        $order = $client->hostedPaymentService()->getOrder(new Order(array('id' => $_GET['id'])));
        if ($order->transaction->status == 'success') {
            if ($sessionOrder->totalAmount != $order->transaction->amount) {
                die('Invalid amount.');
            }
            die('Payment successful! ID: ' . $order->id);
        }
        var_dump($order->transaction->status);
        var_dump($order);
        die;
    } catch (OptimalPayments\NetbanxException $e) {
        echo '<pre>';
        var_dump($e->getMessage());
        if ($e->fieldErrors) {
            var_dump($e->fieldErrors);
<?php

require_once 'config.php';
use OptimalPayments\OptimalApiClient;
use OptimalPayments\Environment;
use OptimalPayments\CustomerVault\Profile;
use OptimalPayments\CustomerVault\Address;
use OptimalPayments\CustomerVault\Card;
use OptimalPayments\CardPayments\Authorization;
if ($_POST) {
    $client = new OptimalApiClient($optimalApiKeyId, $optimalApiKeySecret, Environment::TEST, $optimalAccountNumber);
    try {
        $profile = $client->customerVaultService()->createProfile(new Profile(array("merchantCustomerId" => $_POST['merchant_customer_id'], "locale" => "en_US", "firstName" => $_POST['first_name'], "lastName" => $_POST['last_name'], "email" => $_POST['email'])));
        $address = $client->customerVaultService()->createAddress(new Address(array("nickName" => "home", 'street' => $_POST['street'], 'city' => $_POST['city'], 'state' => $_POST['state'], 'country' => $_POST['country'], 'zip' => $_POST['zip'], "profileID" => $profile->id)));
        $card = $client->customerVaultService()->createCard(new Card(array("nickName" => "Default Card", 'cardNum' => $_POST['card_number'], 'cardExpiry' => array('month' => $_POST['card_exp_month'], 'year' => $_POST['card_exp_year']), 'billingAddressId' => $address->id, "profileID" => $profile->id)));
        $auth = $client->cardPaymentService()->authorize(new Authorization(array('merchantRefNum' => $_POST['merchant_ref_num'], 'amount' => $_POST['amount'] * $currencyBaseUnitsMultiplier, 'settleWithAuth' => true, 'card' => array('paymentToken' => $card->paymentToken))));
        die('Payment successful! ID: ' . $auth->id);
    } catch (OptimalPayments\NetbanxException $e) {
        echo '<pre>';
        var_dump($e->getMessage());
        if ($e->fieldErrors) {
            var_dump($e->fieldErrors);
        }
        if ($e->links) {
            var_dump($e->links);
        }
        echo '</pre>';
    } catch (\OptimalPayments\OptimalException $e) {
        var_dump($e->getMessage());
    }
}