Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
v1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ao committed May 19, 2015
1 parent b48f157 commit c0ec8aa
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 54 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 1.5 2015-05-19
* Modify PHP library timeout period and message

### 1.4 2015-03-04
* PHP 5.2 Error Exeption Handling
* Authorisations
Expand Down
2 changes: 1 addition & 1 deletion examples/3ds_redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?php

/**
* PHP library version:
* PHP library version: v1.5
*/
require_once('../lib/worldpay.php');

Expand Down
2 changes: 1 addition & 1 deletion examples/cancel_authorised_order.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<?php
/**
* PHP library version:
* PHP library version: v1.5
*/
require_once('../lib/worldpay.php');

Expand Down
2 changes: 1 addition & 1 deletion examples/capture_authorised_order.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<?php
/**
* PHP library version:
* PHP library version: v1.5
*/
require_once('../lib/worldpay.php');

Expand Down
3 changes: 2 additions & 1 deletion examples/create_order.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<?php
/**
* PHP library version:
* PHP library version: v1.5
*/
require_once('../lib/worldpay.php');

Expand Down Expand Up @@ -38,6 +38,7 @@
'amount' => $amount*100, // Amount in pence
'is3DSOrder' => $_3ds, // 3DS
'authoriseOnly' => $authoriseOnly,
'orderType' => $_POST['order-type'], //Order Type: ECOM/MOTO/RECURRING
'currencyCode' => $_POST['currency'], // Currency code
'name' => ($_3ds) ? '3D' : $name, // Customer name
'billingAddress' => $billing_address, // Billing address array
Expand Down
2 changes: 1 addition & 1 deletion examples/get_stored_cards.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<?php
/**
* PHP library version:
* PHP library version: v1.5
*/
require_once('../lib/worldpay.php');

Expand Down
70 changes: 39 additions & 31 deletions examples/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@
<input type="text" id="description" name="description" value="My test order" />
</div>

<div class="form-row">
<label>Order Type:</label>
<select id="order-type" name="order-type">
<option value="ECOM" selected>ECOM</option>
<option value="MOTO">MOTO</option>
</select>
</div>

<div class="form-row">
<label>Reusable Token:</label>
<input type="checkbox" id="chkReusable" />
Expand All @@ -146,41 +154,41 @@

</div>

<small>



</small>

<script type="text/javascript">
if (!Worldpay) {
alert('Worldpay JS not loaded!');
if (!window['Worldpay']) {
document.getElementById('place-order').disabled = true;
}
else {
// Set client key
Worldpay.setClientKey("your-client-key");
// Get form element
var form = $('#my-payment-form')[0];
Worldpay.useForm(form, function (status, response) {
if (response.error) {
Worldpay.handleError(form, $('#my-payment-form .payment-errors')[0], response.error);
} else if (status != 200) {
Worldpay.handleError(form, $('#my-payment-form .payment-errors')[0], response);
} else {
var token = response.token;
Worldpay.formBuilder(form, 'input', 'hidden', 'token', token);
$('#my-payment-form .token').html("Your token is: " + token);
form.submit();
}
});

$('#chkReusable').change(function(){
if ($(this).is(':checked')) {
Worldpay.reusable = true;
}
else {
Worldpay.reusable = false;
}
});
}

// Set client key
Worldpay.setClientKey("your-client-key");

// Get form element
var form = $('#my-payment-form')[0];
Worldpay.useForm(form, function (status, response) {
if (response.error) {
Worldpay.handleError(form, $('#my-payment-form .payment-errors')[0], response.error);
} else if (status != 200) {
Worldpay.handleError(form, $('#my-payment-form .payment-errors')[0], response);
} else {
var token = response.token;
Worldpay.formBuilder(form, 'input', 'hidden', 'token', token);
$('#my-payment-form .token').html("Your token is: " + token);
form.submit();
}
});

$('#chkReusable').change(function(){
if ($(this).is(':checked')) {
Worldpay.reusable = true;
}
else {
Worldpay.reusable = false;
}
});
$('#chkReusable').prop('checked', false);
</script>

Expand Down
2 changes: 1 addition & 1 deletion examples/partial_refund_order.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<?php
/**
* PHP library version:
* PHP library version: v1.5
*/
require_once('../lib/worldpay.php');

Expand Down
2 changes: 1 addition & 1 deletion examples/refund_order.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<?php
/**
* PHP library version:
* PHP library version: v1.5
*/
require_once('../lib/worldpay.php');

Expand Down
34 changes: 19 additions & 15 deletions lib/worldpay.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* PHP library version:
* PHP library version: v1.5
*/

final class Worldpay
Expand All @@ -12,10 +12,11 @@ final class Worldpay
* */

private $service_key = "";
private $timeout = 10;
private $timeout = 65;
private $disable_ssl = false;
private $endpoint = 'https://api.worldpay.com/v1/';
private static $use_external_JSON = false;
private $order_types = ['ECOM', 'MOTO', 'RECURRING'];

private static $errors = array(
"ip" => "Invalid parameters",
Expand Down Expand Up @@ -45,7 +46,8 @@ final class Worldpay
),
'json' => 'JSON could not be decoded',
'key' => 'Please enter your service key',
'sslerror' => 'Worldpay SSL certificate could not be validated'
'sslerror' => 'Worldpay SSL certificate could not be validated',
'timeouterror'=> 'Gateway timeout - possible order failure. Please review the order in the portal to confirm success.'
);

/**
Expand Down Expand Up @@ -80,7 +82,7 @@ public function __construct($service_key = false, $timeout = false)
private function getClientIp()
{
$ipaddress = '';

if (isset($_SERVER['HTTP_CLIENT_IP'])) {
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
} elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
Expand Down Expand Up @@ -174,7 +176,7 @@ private function sendRequest($action, $json = false, $expectResponse = false, $m
}

$clientUserAgent = 'os.name=' . php_uname('s') . ';os.version=' . php_uname('r') . ';os.arch=' .
$arch . ';lang.version='. phpversion() . ';lib.version=;' .
$arch . ';lang.version='. phpversion() . ';lib.version=v1.5;' .
'api.version=v1;lang=php;owner=worldpay';

curl_setopt(
Expand All @@ -194,7 +196,7 @@ private function sendRequest($action, $json = false, $expectResponse = false, $m
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}


$result = curl_exec($ch);
$info = curl_getinfo($ch);
Expand All @@ -206,6 +208,8 @@ private function sendRequest($action, $json = false, $expectResponse = false, $m
if ($result === false) {
if ($errno === 60) {
self::onError('sslerror', false, $errno, null, $err);
} else if ($errno === 28) {
self::onError('timeouterror', false, $errno, null, $err);
} else {
self::onError('uanv', false, $errno, null, $err);
}
Expand All @@ -222,7 +226,7 @@ private function sendRequest($action, $json = false, $expectResponse = false, $m
if ($expectResponse && ($response === null || $response === false )) {
self::onError('uanv', self::$errors['json'], 503);
}

// Check the status code exists
if (isset($response["httpStatusCode"])) {

Expand All @@ -241,7 +245,7 @@ private function sendRequest($action, $json = false, $expectResponse = false, $m
} elseif ($expectResponse && $info['http_code'] != 200) {
// If we expect a result and we have an error
self::onError('uanv', self::$errors['json'], 503);

} elseif (!$expectResponse) {

if ($info['http_code'] != 200) {
Expand Down Expand Up @@ -275,21 +279,21 @@ public function createOrder($order = array())
);

$order = array_merge($defaults, $order);

$obj = array(
"token" => $order['token'],
"orderDescription" => $order['orderDescription'],
"amount" => $order['amount'],
"is3DSOrder" => ($order['is3DSOrder']) ? true : false,
"currencyCode" => $order['currencyCode'],
"name" => $order['name'],
"orderType" => $order['orderType'],
"orderType" => (in_array($order['orderType'], $this->order_types)) ? $order['orderType'] : 'ECOM',
"authorizeOnly" => ($order['authoriseOnly']) ? true : false,
"billingAddress" => $order['billingAddress'],
"customerOrderCode" => $order['customerOrderCode'],
"customerIdentifiers" => $order['customerIdentifiers']
);

if ($obj['is3DSOrder']) {
$_SESSION['worldpay_sessionid'] = uniqid();
$obj['shopperIpAddress'] = $this->getClientIp();
Expand All @@ -299,7 +303,7 @@ public function createOrder($order = array())
}

$json = json_encode($obj);

$response = $this->sendRequest('orders', $json, true);

if (isset($response["orderCode"])) {
Expand All @@ -309,7 +313,7 @@ public function createOrder($order = array())
self::onError("apierror");
}
}

/**
* Authorise Worldpay 3DS Order
* @param string $orderCode
Expand Down Expand Up @@ -381,7 +385,7 @@ public function refundOrder($orderCode = false, $amount = null)
}

/**
* Get card details from Worldpay token
* Get card details from Worldpay token
* @param string $token
* @return array card details
* */
Expand All @@ -395,7 +399,7 @@ public function getStoredCardDetails($token = false)
if (!isset($response['paymentMethod'])) {
self::onError("apierror");
}

return $response['paymentMethod'];
}

Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Worldpay PHP Library
# Worldpay PHP Library v1.5

#### Documentation
https://online.worldpay.com/docs
Expand Down

0 comments on commit c0ec8aa

Please sign in to comment.