// Something went wrong echo '<p id="payment-status">' . $response['paymentStatus'] . '</p>'; throw new WorldpayException(print_r($response, true)); } } else { $obj = array('orderDescription' => $_POST['description'], 'amount' => $amount, 'is3DSOrder' => $_3ds, 'authorizeOnly' => $authorizeOnly, 'siteCode' => $_POST['site-code'], 'orderType' => $_POST['order-type'], 'currencyCode' => $_POST['currency'], 'settlementCurrency' => $_POST['settlement-currency'], 'name' => $_3ds && true ? '3D' : $name, 'shopperEmailAddress' => $shopperEmailAddress, 'billingAddress' => $billing_address, 'deliveryAddress' => $delivery_address, 'customerIdentifiers' => !is_null($customerIdentifiers) ? $customerIdentifiers : array(), 'statementNarrative' => $_POST['statement-narrative'], 'orderCodePrefix' => $_POST['code-prefix'], 'orderCodeSuffix' => $_POST['code-suffix'], 'customerOrderCode' => 'A123'); if ($directOrder) { $obj['directOrder'] = true; $obj['shopperLanguageCode'] = isset($_POST['language-code']) ? $_POST['language-code'] : ""; $obj['reusable'] = isset($_POST['chkReusable']) && $_POST['chkReusable'] == 'on' ? true : false; $obj['paymentMethod'] = array("name" => $_POST['name'], "expiryMonth" => $_POST['expiration-month'], "expiryYear" => $_POST['expiration-year'], "cardNumber" => $_POST['card'], "cvc" => $_POST['cvc']); } else { $obj['token'] = $token; // The token from WorldpayJS } $response = $worldpay->createOrder($obj); if ($response['paymentStatus'] === 'SUCCESS' || $response['paymentStatus'] === 'AUTHORIZED') { // Create order was successful! $worldpayOrderCode = $response['orderCode']; echo '<p>Order Code: <span id="order-code">' . $worldpayOrderCode . '</span></p>'; echo '<p>Token: <span id="token">' . $response['token'] . '</span></p>'; echo '<p>Payment Status: <span id="payment-status">' . $response['paymentStatus'] . '</span></p>'; echo '<pre>' . print_r($response, true) . '</pre>'; // TODO: Store the order code somewhere.. } elseif ($response['is3DSOrder']) { // Redirect to URL // STORE order code in session $_SESSION['orderCode'] = $response['orderCode']; ?> <form id="submitForm" method="post" action="<?php echo $response['redirectURL'];
// DONT USE IN PRODUCTION $worldpay->disableSSLCheck(true); $token = $_POST['token']; $name = $_POST['name']; $amount = $_POST['amount']; $_3ds = isset($_POST['3ds']) ? $_POST['3ds'] : false; $authoriseOnly = isset($_POST['authoriseOnly']) ? $_POST['authoriseOnly'] : false; $customerIdentifiers = !empty($_POST['customer-identifiers']) ? json_decode($_POST['customer-identifiers']) : array(); include 'header.php'; // Try catch try { // Customers billing address $billing_address = array("address1" => $_POST['address1'], "address2" => $_POST['address2'], "address3" => $_POST['address3'], "postalCode" => $_POST['postcode'], "city" => $_POST['city'], "state" => '', "countryCode" => $_POST['countryCode']); // Customers delivery address $delivery_address = array("firstName" => $_POST['delivery-firstName'], "lastName" => $_POST['delivery-lastName'], "address1" => $_POST['delivery-address1'], "address2" => $_POST['delivery-address2'], "address3" => $_POST['delivery-address3'], "postalCode" => $_POST['delivery-postcode'], "city" => $_POST['delivery-city'], "state" => '', "countryCode" => $_POST['delivery-countryCode']); $response = $worldpay->createOrder(array('token' => $token, 'orderDescription' => $_POST['description'], 'amount' => $amount * 100, 'is3DSOrder' => $_3ds, 'authoriseOnly' => $authoriseOnly, 'orderType' => $_POST['order-type'], 'currencyCode' => $_POST['currency'], 'settlementCurrency' => $_POST['settlement-currency'], 'name' => $_3ds ? '3D' : $name, 'billingAddress' => $billing_address, 'deliveryAddress' => $delivery_address, 'customerIdentifiers' => !is_null($customerIdentifiers) ? $customerIdentifiers : array(), 'statementNarrative' => $_POST['statement-narrative'], 'customerOrderCode' => 'A123')); if ($response['paymentStatus'] === 'SUCCESS' || $response['paymentStatus'] === 'AUTHORIZED') { // Create order was successful! $worldpayOrderCode = $response['orderCode']; echo '<p>Order Code: <span id="order-code">' . $worldpayOrderCode . '</span></p>'; echo '<p>Token: <span id="token">' . $response['token'] . '</span></p>'; echo '<p>Payment Status: <span id="payment-status">' . $response['paymentStatus'] . '</span></p>'; echo '<pre>' . print_r($response, true) . '</pre>'; // TODO: Store the order code somewhere.. } elseif ($response['is3DSOrder']) { // Redirect to URL // STORE order code in session $_SESSION['orderCode'] = $response['orderCode']; ?> <form id="submitForm" method="post" action="<?php echo $response['redirectURL'];
// Initialise Worldpay class with your SERVICE KEY $worldpay = new Worldpay("your-service-key"); // Sometimes your SSL doesnt validate locally // DONT USE IN PRODUCTION $worldpay->disableSSLCheck(true); $token = $_POST['token']; $name = $_POST['name']; $amount = $_POST['amount']; $_3ds = isset($_POST['3ds']) ? $_POST['3ds'] : false; $authoriseOnly = isset($_POST['authoriseOnly']) ? $_POST['authoriseOnly'] : false; include 'header.php'; // Try catch try { // Customers billing address $billing_address = array("address1" => $_POST['address1'], "address2" => $_POST['address2'], "address3" => $_POST['address3'], "postalCode" => $_POST['postcode'], "city" => $_POST['city'], "state" => '', "countryCode" => $_POST['countryCode']); $response = $worldpay->createOrder(array('token' => $token, 'orderDescription' => $_POST['description'], 'amount' => $amount * 100, 'is3DSOrder' => $_3ds, 'authoriseOnly' => $authoriseOnly, 'orderType' => $_POST['order-type'], 'currencyCode' => $_POST['currency'], 'name' => $_3ds ? '3D' : $name, 'billingAddress' => $billing_address, 'customerIdentifiers' => array('my-customer-ref' => 'customer-ref'), 'customerOrderCode' => 'A123')); if ($response['paymentStatus'] === 'SUCCESS' || $response['paymentStatus'] === 'AUTHORIZED') { // Create order was successful! $worldpayOrderCode = $response['orderCode']; echo '<p>Order Code: <span id="order-code">' . $worldpayOrderCode . '</span></p>'; echo '<p>Token: <span id="token">' . $response['token'] . '</span></p>'; echo '<p>Payment Status: <span id="payment-status">' . $response['paymentStatus'] . '</span></p>'; echo '<pre>' . print_r($response, true) . '</pre>'; // TODO: Store the order code somewhere.. } elseif ($response['is3DSOrder']) { // Redirect to URL // STORE order code in session $_SESSION['orderCode'] = $response['orderCode']; ?> <form id="submitForm" method="post" action="<?php echo $response['redirectURL'];