You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
4.8 KiB
PHP
124 lines
4.8 KiB
PHP
<?php
|
|
/*
|
|
* Cart page - Shortcut Flow.
|
|
*/
|
|
session_start();
|
|
$rootPath = "";
|
|
include_once('api/Config/Config.php');
|
|
include_once('api/Config/Sample.php');
|
|
include_once('api/Helpers/DbHelper.php');
|
|
include('templates/header.php');
|
|
$baseUrl = str_replace("index.php", "", URL['current']);
|
|
$lan = isset($_GET['language']) ? $_GET['language'] : 'zh';
|
|
$text = LAN[$lan];
|
|
?>
|
|
|
|
<!-- HTML Content -->
|
|
<div class="row-fluid">
|
|
<!-- Left Section -->
|
|
<div class="col-md-3" id="leftSection">
|
|
<div class="card">
|
|
<img class="card-img-top img-responsive" src="<?= $rootPath ?>img/icon.png">
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Middle Section -->
|
|
<div class="col-md-4 form-horizontal">
|
|
<h3 class="text-center"><?= isset($_GET['title']) ? $_GET['title'] : '-'; ?></h3>
|
|
<div class="form-group">
|
|
<label class="col-sm-5 control-label"><?= $text['gift'] ?></label>
|
|
<div class="col-sm-7">
|
|
<table class="table table-striped">
|
|
<tbody>
|
|
<?php if (!empty($_GET['item'])) :
|
|
foreach ($_GET['item'] as $k => $i) : ?>
|
|
<tr>
|
|
<td><?= $k + 1; ?></td>
|
|
<td><?= $i['name']; ?></td>
|
|
<td>x <?= $i['num']; ?></td>
|
|
</tr>
|
|
<?php endforeach;
|
|
endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<form class="form-horizontal">
|
|
<div class="form-group">
|
|
<label for="total_amt" class="col-sm-5 control-label"><?= $text['price'] ?></label>
|
|
<div class="col-sm-7">
|
|
<input class="form-control" type="text" id="total_amt" name="total_amt" value="<?= isset($_GET['price']) ? $_GET['price'] : 0 ?>" readonly>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Checkout Options -->
|
|
<div class="form-group">
|
|
<div class="col-sm-offset-5 col-sm-7">
|
|
<!-- Container for PayPal Shortcut Checkout -->
|
|
<div id="paypalCheckoutContainer"></div>
|
|
|
|
<!-- Container for PayPal Mark Redirect -->
|
|
<div id="paypalMarkRedirect"></div>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<!-- Javascript Import -->
|
|
<script src="https://www.paypal.com/sdk/js?client-id=<?= PAYPAL_CREDENTIALS[PAYPAL_ENVIRONMENT]['client_id']; ?>&intent=capture&vault=false&commit=true<?php echo isset($_GET['buyer-country']) ? "&buyer-country=" . $_GET['buyer-country'] : "" ?>"></script>
|
|
<script src="<?= $rootPath ?>js/config.js"></script>
|
|
|
|
<!-- PayPal In-Context Checkout script -->
|
|
<script type="text/javascript">
|
|
paypal.Buttons({
|
|
|
|
// Set your environment
|
|
env: '<?= PAYPAL_ENVIRONMENT ?>',
|
|
|
|
// Set style of buttons
|
|
style: {
|
|
layout: 'vertical', // horizontal | vertical
|
|
size: 'responsive', // medium | large | responsive
|
|
shape: 'pill', // pill | rect
|
|
color: 'gold', // gold | blue | silver | black,
|
|
fundingicons: false, // true | false,
|
|
tagline: false // true | false,
|
|
},
|
|
|
|
// Wait for the PayPal button to be clicked
|
|
createOrder: function() {
|
|
let formData = new FormData();
|
|
formData.append('orderid', '<?= isset($_GET['orderid']) ? $_GET['orderid'] : ''; ?>');
|
|
formData.append('total_amt', document.getElementById("total_amt").value);
|
|
formData.append('desc', '<?= isset($_GET['title']) ? $_GET['title'] : ''; ?>');
|
|
formData.append('lan', '<?= $lan; ?>');
|
|
formData.append('return_url', '<?= $baseUrl . URL["redirectUrls"]["returnUrl"] ?>' + '?commit=true');
|
|
formData.append('cancel_url', '<?= $baseUrl . URL["redirectUrls"]["cancelUrl"] ?>');
|
|
return fetch(
|
|
'<?= $rootPath . URL['services']['orderCreate'] ?>', {
|
|
method: 'POST',
|
|
body: formData
|
|
}
|
|
).then(function(response) {
|
|
return response.json();
|
|
}).then(function(resJson) {
|
|
console.log('Order ID: ' + resJson.data.id);
|
|
return resJson.data.id;
|
|
});
|
|
},
|
|
|
|
// Wait for the payment to be authorized by the customer
|
|
onApprove: function(data, actions) {
|
|
return fetch(
|
|
'<?= $rootPath . URL['services']['orderGet'] ?>', {
|
|
method: 'GET'
|
|
}
|
|
).then(function(res) {
|
|
return res.json();
|
|
}).then(function(res) {
|
|
window.location.href = 'pages/success.php';
|
|
});
|
|
}
|
|
|
|
}).render('#paypalCheckoutContainer');
|
|
</script>
|