$apmFields = array(); if (isset($_POST['swiftCode'])) { $apmFields['swiftCode'] = $_POST['swiftCode']; } if (isset($_POST['shopperBankCode'])) { $apmFields['shopperBankCode'] = $_POST['shopperBankCode']; } if (empty($apmFields)) { $apmFields = new stdClass(); } $obj['paymentMethod'] = array("apmName" => $_POST['apm-name'], "shopperCountryCode" => $_POST['countryCode'], "apmFields" => $apmFields); } else { $obj['token'] = $token; // The token from WorldpayJS } $response = $worldpay->createApmOrder($obj); if ($response['paymentStatus'] === 'PRE_AUTHORIZED') { // Redirect to URL $_SESSION['orderCode'] = $response['orderCode']; ?> <script> window.location.replace("<?php echo $response['redirectURL']; ?> "); </script> <?php } else { // Something went wrong echo '<p id="payment-status">' . $response['paymentStatus'] . '</p>'; throw new WorldpayException(print_r($response, true));
// DONT USE IN PRODUCTION $worldpay->disableSSLCheck(true); $token = $_POST['token']; $name = $_POST['name']; $amount = $_POST['amount']; $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://"; $redirect_url = $protocol . $_SERVER['HTTP_HOST'] . "/apm"; $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->createApmOrder(array('token' => $token, 'orderDescription' => $_POST['description'], 'amount' => $amount * 100, 'currencyCode' => $_POST['currency'], 'settlementCurrency' => $_POST['settlement-currency'], 'name' => $name, 'billingAddress' => $billing_address, 'deliveryAddress' => $delivery_address, 'customerIdentifiers' => !is_null($customerIdentifiers) ? $customerIdentifiers : array(), 'statementNarrative' => $_POST['statement-narrative'], 'customerOrderCode' => 'A123', 'successUrl' => $redirect_url . '/success.php', 'pendingUrl' => $redirect_url . '/pending.php', 'failureUrl' => $redirect_url . '/error.php', 'cancelUrl' => $redirect_url . '/cancel.php')); if ($response['paymentStatus'] === 'PRE_AUTHORIZED') { // Redirect to URL $_SESSION['orderCode'] = $response['orderCode']; ?> <script> window.location.replace("<?php echo $response['redirectURL']; ?> "); </script> <?php // TODO: Store the order code somewhere.. } else { // Something went wrong echo '<p id="payment-status">' . $response['paymentStatus'] . '</p>';