Skip to content

Commit

Permalink
Tool - Add eventsCode function
Browse files Browse the repository at this point in the history
  • Loading branch information
yidas committed Dec 17, 2020
1 parent 8977fe7 commit 4be1317
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
43 changes: 41 additions & 2 deletions tool/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function formSubmit(form) {
else if (form.transactionId.value) {
form.action = "details.php";
}
form.form.submit();
form.submit();
return;
}
</script>
Expand Down Expand Up @@ -303,6 +303,17 @@ function formSubmit(form) {
<input type="number" name="rewardLimit" class="form-control" placeholder="options.extra.promotionRestriction.rewardLimit">
</div>
<hr>
<div class="row">
<div class="col col-9 col-md-9">
<label>Events Code: <code>events</code> <font color="#cccccc"><i>(Offline Only)</i></font></label>
</div>
<div class="col col-3 col-md-3">
<button class="btn btn-sm btn-outline-secondary float-right btn-events-code-add" type="button">Add</button>
</div>
</div>
<div id="eventsCodeBlock">
</div>
<hr>
<div class="form-group">
<label>Search Transaction <font color="#cccccc"><i>(Effective with Custom merchant & Sandbox setting)</i></font></label>
<div class="input-group">
Expand Down Expand Up @@ -347,6 +358,29 @@ function formSubmit(form) {
</div>
</form>

<!-- Template -->
<script type="text/template" id="eventsCodeTemplate">
<div class="input-group input-group-sm">
<div class="input-group-prepend">
<span class="input-group-text" style="min-width: 120px;">Code</span>
</div>
<input type="text" name="eventsCode[]" class="form-control" placeholder="extras.events.code">
</div>
<div class="input-group input-group-sm">
<div class="input-group-prepend">
<span class="input-group-text" style="min-width: 120px;">TotalAmount</span>
</div>
<input type="number" name="eventsTotalAmount[]" class="form-control" placeholder="extras.events.totalAmount">
</div>
<div class="input-group input-group-sm">
<div class="input-group-prepend">
<span class="input-group-text" style="min-width: 120px;">Quantity</span>
</div>
<input type="number" name="eventsProductQuantity[]" class="form-control" placeholder="extras.events.productQuantity">
</div>
</script>
<!-- /Template -->

<?php endif ?>

<!-- Modal for log -->
Expand Down Expand Up @@ -414,7 +448,12 @@ function formSubmit(form) {
});
}

<?php if($merchant && (!$config || isset($config['merchant']))): ?>
// EventCode Add Button
$(".btn-events-code-add").click(function () {
$("#eventsCodeBlock").append($("#eventsCodeTemplate").html()).append("<br>");
});

<?php if($merchants && (!$config || isset($config['merchant']))): ?>
// Action for merchant config condition
$(".merchant-block[data-block-id='custom']").find(".btn-merchant-switch").click();
<?php endif ?>
Expand Down
11 changes: 10 additions & 1 deletion tool/onetimekeys-pay.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
'amount' => (integer) $input['amount'],
'currency' => $input['currency'],
'orderId' => $orderId,
'oneTimeKey' => $input['otk'],
'oneTimeKey' => $input['otk'],
];

// Capture: false
Expand All @@ -46,6 +46,15 @@
$orderParams['extras']['promotionRestriction']['useLimit'] = ($input['useLimit']) ? $input['useLimit'] : 0;
$orderParams['extras']['promotionRestriction']['rewardLimit'] = ($input['rewardLimit']) ? $input['rewardLimit'] : 0;
}
// Events Code
if (isset($input['eventsCode'][0])) {
for ($i=0; $i < count($input['eventsCode']); $i++) {
$orderParams['extras']['events'][$i]['code'] = ($input['eventsCode'][$i]) ? $input['eventsCode'][$i] : "";
$orderParams['extras']['events'][$i]['totalAmount'] = ($input['eventsTotalAmount'][$i]) ? (integer) $input['eventsTotalAmount'][$i] : 0;
$orderParams['extras']['events'][$i]['productQuantity'] = ($input['eventsProductQuantity'][$i]) ? (integer) $input['eventsProductQuantity'][$i] : 0;
}
}

// Request Body Rewriting
$orderParams = ($input['requestBody']) ? json_decode($input['requestBody'], true) : $orderParams;

Expand Down

0 comments on commit 4be1317

Please sign in to comment.