Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
vendor/*
config.php
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Spreedly

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# sample-payment-frame

An example implementation of a payment page using the Spreedly iFrame payment collection form.
An example implementation of a payment page using the Spreedly iFrame payment collection form and TourCMS API for 3D Secure 2 payments.

You can see this form live at [https://spreedly-payment-frame.herokuapp.com](https://spreedly-payment-frame.herokuapp.com).

All logic is contained in `index.html`. The other files in this repo
exist to support deploying this app to Heroku. If you've cloned the
repo locally, you can just open `index.html` in your browser.
Duplicate `config-example.php` as `config.php` and load your TourCMS API credentials. Set your currency, and a valid TourCMS booking ID.
27 changes: 27 additions & 0 deletions complete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
include_once('config.php');
$transaction_id = $_GET['transaction_id'];

$response = $tourcms->request('/c/booking/gatewaytransaction/spreedlycomplete.xml?id=' . $transaction_id, $channel_id, 'POST', null);
error_log("FINAL PAGE ". print_r($response, TRUE));

$transaction = array(
'state' => (string)$response->booking->transaction->state,
'succeeded' => (string)$response->booking->transaction->succeeded,
'message' => (string)$response->booking->transaction->message,
'token' => (string)$response->booking->transaction->transaction_token,
'required_action' => (string)$response->booking->transaction->required_action,
'checkout_url' => (string)$response->booking->transaction->checkout_url,
'checkout_form' => array(
'cdata' => htmlspecialchars_decode((string)$response->booking->transaction->checkout_form)
),
'device_fingerprint_form' => array(
'cdata' => htmlspecialchars_decode((string)$response->booking->transaction->device_fingerprint_form)
),
'challenge_url' => (string)$response->booking->transaction->challenge_url
);

header("Content-type: application/json");
echo json_encode($transaction);
//print $response->booking->transaction->transaction_json;
?>
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"tourcms/tourcms-php": "^3.3"
}
}
66 changes: 66 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions config-example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
include_once('vendor/autoload.php');
// TourCMS API

use TourCMS\Utils\TourCMS as TourCMS;

$tourcms_api_key = '';

$marketplace_id = 0;

$channel_id = 0;

$tourcms = new TourCMS($marketplace_id, $tourcms_api_key, 'simplexml');

$sly_booking_id = 0;

$sly_currency = 'EUR';

$attempt_3dsecure = true;

//$tourcms->set_base_url('http://localhost/api.tourcms.com');

// Set up Spreedly object

// Environment (e.g. Test)
$sly_environment = '9xyyNh89TMduskMtOTh48V2wrJ8';


$sly_redirect_url = 'https://www.example.com';

?>
47 changes: 45 additions & 2 deletions index.html → index.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
<!DOCTYPE html>
<?php
include('config.php');
?><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Spreedly Sample iFrame Payment Page</title>
<link rel="stylesheet" type="text/css" href="css/styles.css">
<script src="https://core.spreedly.com/iframe/iframe-v1.min.js"></script>
<script src="js/3dsecure2.js"></script>
</head>

<body>

<input type="hidden" id="aceptheadercapture" value=<?php echo htmlspecialchars($_SERVER["HTTP_ACCEPT"]); ?>>

<form id="payment-form" accept-charset="UTF-8" class="spf-form" method="POST"
action="#" onsubmit="submitPaymentForm(); return false;">

Expand Down Expand Up @@ -60,6 +65,22 @@ <h2>Billing Address</h2>
<fieldset class="spf-fs-cc">
<h2>Payment Details</h2>

<div class="spf-field spf-field-exp">
<label>Amount</label>
<div class="spf-field-group">
<select id="amount-input" class="spf-input-text" style="width: 90%">
<option value="30.01">3001 - 3D Secure 2 full frictionless flow (immediate transaction flow)</option>
<option value="30.02">3002 - Fallback from 3DS2 to 3DS1</option>
<option value="30.03">3003 - 3D Secure device fingerprint flow with direct authorize (requires lifecycle)</option>
<option value="30.04">3004 - 3D Secure device fingerprint flow to challenge (requires lifecycle and completion call)</option>
<option value="30.05">3005 - 3D Secure direct challenge (requires lifecycle and completion call)</option>
<option value="31.03">3103 - 3D Secure device fingerprint flow with forced failure</option>
<option value="31.04">3104 - 3D Secure challenge flow with forced failure</option>
</select>
<!-- <label class="spf-label-secondary" for="spf-exp-m">Month (MM)</label> -->
</div>
</div>

<div class="spf-field">
<label class="spf-field-group spf-number">Credit Card Number</label>
<label class="spf-field-group spf-verification_value">CVV</label>
Expand All @@ -83,6 +104,9 @@ <h2>Payment Details</h2>
</div>
</fieldset>




<fieldset class="spf-field-submit">
<input type="submit" class="button" value="Submit Payment">
<div id="message"></div>
Expand All @@ -91,12 +115,22 @@ <h2>Payment Details</h2>

<script
id="spreedly-iframe"
data-environment-key="TbWAYgG7qaagGBh7hPjXQxS4DM4"
data-environment-key="<?php echo $sly_environment; ?>"
data-number-id="spreedly-number-test"
data-cvv-id="spreedly-cvv-test">
</script>
</form>

<fieldset class="spf-fs-cc">
<div class="spf-field">
Hidden fields:
<div id="spreedly-threeds-hidden-iframe"></div>

<div id="spreedly-threeds-challenge-iframe"></div>

</div>
</fieldset>

<script>
Spreedly.init();

Expand All @@ -111,6 +145,15 @@ <h2>Payment Details</h2>
// For demonstration purposes just display the token
var messageEl = document.getElementById('message');
messageEl.innerHTML = "Success! The returned payment method token is: " + token;

var amountBox = document.getElementById("amount-input");

sendPayment({
'amount': amountBox.options[amountBox.selectedIndex].value,
'currency_code':'USD',
'payment_method_token':token,
'order_id': ''
});
});

Spreedly.on('errors', function(errors) {
Expand Down
Loading