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

Commit

Permalink
v1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ao committed Mar 4, 2015
1 parent 27f7166 commit f9e4c48
Show file tree
Hide file tree
Showing 18 changed files with 218 additions and 51 deletions.
Empty file modified LICENSE
100755 → 100644
Empty file.
8 changes: 6 additions & 2 deletions examples/3ds_redirect.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?php

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

Expand All @@ -13,6 +13,8 @@
// DONT USE IN PRODUCTION
$worldpay->disableSSLCheck(true);

include('header.php');

try {
$response = $worldpay->authorise3DSOrder($_SESSION['orderCode'], $_POST['PaRes']);

Expand All @@ -21,11 +23,13 @@
} else {
echo 'There was a problem authorising 3DS order <br/>';
}
} catch (WorldpayException $e) { // PHP 5.2 - Change to Exception, only $e->getMessage() is available
} catch (WorldpayException $e) { // PHP 5.3+
// Worldpay has thrown an exception
echo 'Error code: ' . $e->getCustomCode() . '<br/>
HTTP status code:' . $e->getHttpStatusCode() . '<br/>
Error description: ' . $e->getDescription() . ' <br/>
Error message: ' . $e->getMessage() . ' <br/>' .
'PaRes: ' . print_r($_POST, true) . '<br/>';
} catch (Exception $e) { // PHP 5.2
echo 'Error message: '. $e->getMessage();
}
17 changes: 17 additions & 0 deletions examples/cancel_authorised_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php include("header.php"); ?>
<h1>PHP Library Cancel Authorised Order Example</h1>
<form method="post" action="cancel_authorised_order.php" id="cancel-authorised-order-form">
<div class="payment-errors"></div>
<div class="form-row">
<label>
Worldpay Order Code
</label>
<input type="text" id="order-code" name="orderCode" value="" />
</div>
<input type="submit" id="cancel-order" value="Cancel Authorised Order" />
</form>

</div>

</body>
</html>
33 changes: 33 additions & 0 deletions examples/cancel_authorised_order.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

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

// 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);

$worldpayOrderCode = $_POST['orderCode'];

include("header.php");

// Try catch
try {
// Cancel the authorised order using the Worldpay order code
$worldpay->cancelAuthorisedOrder($worldpayOrderCode);
echo 'Authorised order <span id="order-code">'.$worldpayOrderCode.'</span>
has been cancelled';
} catch (WorldpayException $e) { // PHP 5.3+
// Worldpay has thrown an exception
echo 'Error code: ' . $e->getCustomCode() . '<br/>
HTTP status code:' . $e->getHttpStatusCode() . '<br/>
Error description: ' . $e->getDescription() . ' <br/>
Error message: ' . $e->getMessage();
} catch (Exception $e) { // PHP 5.2
echo 'Error message: '. $e->getMessage();
}
21 changes: 21 additions & 0 deletions examples/capture_authorised_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php include("header.php"); ?>
<h1>PHP Library Capture Authorised Order Example</h1>
<form method="post" action="capture_authorised_order.php" id="capture-authorised-order-form">
<div class="payment-errors"></div>
<div class="form-row">
<label>
Worldpay Order Code
</label>
<input type="text" id="order-code" name="orderCode" value="" />
</div>
<div class="form-row">
<label>
Amount
</label>
<input type="text" id="amount" name="amount" value="" />
</div>
<input type="submit" id="capture-order" value="Capture Authorised Order" />
</form>
</div>
</body>
</html>
36 changes: 36 additions & 0 deletions examples/capture_authorised_order.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

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

// 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);

$worldpayOrderCode = $_POST['orderCode'];
$amount = $_POST['amount'];

include("header.php");

// Try catch
try {
// Capture the authorised order using the Worldpay order code
$worldpay->captureAuthorisedOrder($worldpayOrderCode, $amount*100);
$response = 'Authorised order <span id="order-code">'.$worldpayOrderCode.'</span> has been captured for ';
$response .= (!empty($amount)) ? '<span id="amount">'. $amount .'</span>' : 'the full amount';
echo $response;

} catch (WorldpayException $e) { // PHP 5.3+
// Worldpay has thrown an exception
echo 'Error code: ' . $e->getCustomCode() . '<br/>
HTTP status code:' . $e->getHttpStatusCode() . '<br/>
Error description: ' . $e->getDescription() . ' <br/>
Error message: ' . $e->getMessage();
} catch (Exception $e) { // PHP 5.2
echo 'Error message: '. $e->getMessage();
}
12 changes: 8 additions & 4 deletions examples/create_order.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

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

Expand All @@ -16,6 +16,7 @@
$name = $_POST['name'];
$amount = $_POST['amount'];
$_3ds = (isset($_POST['3ds'])) ? $_POST['3ds'] : false;
$authoriseOnly = (isset($_POST['authoriseOnly'])) ? $_POST['authoriseOnly'] : false;

include('header.php');

Expand All @@ -36,6 +37,7 @@
'orderDescription' => $_POST['description'], // Order description of your choice
'amount' => $amount*100, // Amount in pence
'is3DSOrder' => $_3ds, // 3DS
'authoriseOnly' => $authoriseOnly,
'currencyCode' => $_POST['currency'], // Currency code
'name' => ($_3ds) ? '3D' : $name, // Customer name
'billingAddress' => $billing_address, // Billing address array
Expand All @@ -44,8 +46,8 @@
),
'customerOrderCode' => 'A123' // Order code of your choice
));

if ($response['paymentStatus'] === 'SUCCESS') {
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>';
Expand Down Expand Up @@ -73,10 +75,12 @@
echo '<p id="payment-status">' . $response['paymentStatus'] . '</p>';
throw new WorldpayException(print_r($response, true));
}
} catch (WorldpayException $e) { // PHP 5.2 - Change to Exception, only $e->getMessage() is available
} catch (WorldpayException $e) { // PHP 5.3+
// Worldpay has thrown an exception
echo 'Error code: ' . $e->getCustomCode() . '<br/>
HTTP status code:' . $e->getHttpStatusCode() . '<br/>
Error description: ' . $e->getDescription() . ' <br/>
Error message: ' . $e->getMessage();
} catch (Exception $e) { // PHP 5.2
echo 'Error message: '. $e->getMessage();
}
6 changes: 4 additions & 2 deletions examples/get_stored_cards.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

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

Expand All @@ -26,9 +26,11 @@
echo '<p>Masked Card Number: <span id="masked-card-number">' . $cardDetails['maskedCardNumber'] . '</span></p>';
echo '<pre>' . print_r($cardDetails, true). '</pre>';

} catch (WorldpayException $e) { // PHP 5.2 - Change to Exception, only $e->getMessage() is available
} catch (WorldpayException $e) { // PHP 5.3+
echo 'Error code: ' . $e->getCustomCode() . '<br/>
HTTP status code:' . $e->getHttpStatusCode() . '<br/>
Error description: ' . $e->getDescription() . ' <br/>
Error message: ' . $e->getMessage();
} catch (Exception $e) { // PHP 5.2
echo 'Error message: '. $e->getMessage();
}
65 changes: 33 additions & 32 deletions examples/header.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<title>PHP Library</title>
<script src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
<style>
body {
background:#efefef;
Expand All @@ -25,7 +25,6 @@
padding:2px;
padding-left:10px;
}
.form-row label {
width:200px;
text-align:right;
Expand All @@ -37,38 +36,40 @@
padding-left: 10px;
height:25px;
}
.payment-errors {
font-size: 20px;
font-weight: bold;
text-align: center;
color: red;
padding: 20px;
margin-bottom: 20px;
}
.token {
padding-top:20px;
}
#top-nav {
list-style: none;
text-align: center;
}
#top-nav li {
display:inline-block;
}
#top-nav li a {
text-decoration: none;
color:blue;
padding-left: 10px;
}
</style>
.payment-errors {
font-size: 20px;
font-weight: bold;
text-align: center;
color: red;
padding: 20px;
margin-bottom: 20px;
}
.token {
padding-top:20px;
}
#top-nav {
list-style: none;
text-align: center;
}
#top-nav li {
display:inline-block;
}
#top-nav li a {
text-decoration: none;
color:blue;
padding-left: 10px;
}
</style>
</head>
<body>

<div class="container">

<ul id="top-nav">
<li><a href="index.php">Create Order</a></li>
<li><a href="refund.php">Refund</a></li>
<li><a href="partial_refund.php">Partial Refund</a></li>
<li><a href="stored_cards.php">Stored Cards</a></li>
</ul>
<ul id="top-nav">
<li><a href="index.php">Create Order</a></li>&nbsp;&nbsp;|
<li><a href="capture_authorised_form.php">Capture Authorised Order</a></li>&nbsp;&nbsp;|
<li><a href="cancel_authorised_form.php">Cancel Authorised Order</a></li>&nbsp;&nbsp;|
<li><a href="refund.php">Refund</a></li>
<li><a href="partial_refund.php">Partial Refund</a></li>&nbsp;&nbsp;|
<li><a href="stored_cards.php">Stored Cards</a></li>
</ul>
7 changes: 6 additions & 1 deletion examples/index.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

<?php include("header.php"); ?>
<script src=""></script>
<script src="https://cdn.worldpay.com/v1/worldpay.js"></script>
<h1>PHP Library Create Order Example</h1>
<form method="post" action="create_order.php" id="my-payment-form">
<div class="payment-errors"></div>
Expand Down Expand Up @@ -132,6 +132,11 @@
<input type="checkbox" id="chk3Ds" name="3ds" />
</div>

<div class="form-row">
<label>Authorise Only:</label>
<input type="checkbox" id="chkAuthoriseOnly" name="authoriseOnly" />
</div>

<input type="submit" id="place-order" value="Place Order" />
</div>

Expand Down
Empty file modified examples/partial_refund.php
100755 → 100644
Empty file.
12 changes: 8 additions & 4 deletions examples/partial_refund_order.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

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

Expand All @@ -21,12 +21,16 @@
try {
// Refund the order using the Worldpay order code
$worldpay->refundOrder($worldpayOrderCode, $amount*100);
echo 'Order <span id="order-code">'.$worldpayOrderCode.'</span>
has been refunded for <span id="amount">'. $amount .'</span>';
} catch (WorldpayException $e) { // PHP 5.2 - Change to Exception, only $e->getMessage() is available
$response = 'Order <span id="order-code">'.$worldpayOrderCode.'</span> has been refunded for ';
$response .= (!empty($amount)) ? '<span id="amount">'. $amount .'</span>' : 'the full amount';
echo $response;

} catch (WorldpayException $e) { // PHP 5.3+
// Worldpay has thrown an exception
echo 'Error code: ' . $e->getCustomCode() . '<br/>
HTTP status code:' . $e->getHttpStatusCode() . '<br/>
Error description: ' . $e->getDescription() . ' <br/>
Error message: ' . $e->getMessage();
} catch (Exception $e) { // PHP 5.2
echo 'Error message: '. $e->getMessage();
}
Empty file modified examples/refund.php
100755 → 100644
Empty file.
6 changes: 4 additions & 2 deletions examples/refund_order.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

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

Expand All @@ -21,10 +21,12 @@
// Refund the order using the Worldpay order code
$worldpay->refundOrder($worldpayOrderCode);
echo 'Order <span id="order-code">'.$worldpayOrderCode.'</span> has been refunded!';
} catch (WorldpayException $e) { // PHP 5.2 - Change to Exception, only $e->getMessage() is available
} catch (WorldpayException $e) { // PHP 5.3+
// Worldpay has thrown an exception
echo 'Error code: ' . $e->getCustomCode() . '<br/>
HTTP status code:' . $e->getHttpStatusCode() . '<br/>
Error description: ' . $e->getDescription() . ' <br/>
Error message: ' . $e->getMessage();
} catch (Exception $e) { // PHP 5.2
echo 'Error message: '. $e->getMessage();
}
Empty file modified examples/stored_cards.php
100755 → 100644
Empty file.
Empty file modified lib/JSON.php
100755 → 100644
Empty file.
Loading

0 comments on commit f9e4c48

Please sign in to comment.