Skip to content

Commit

Permalink
added enable_cancel_event_on_success
Browse files Browse the repository at this point in the history
  • Loading branch information
alifaraun committed Sep 16, 2024
1 parent 94603d4 commit 05ac177
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ return [
*/
'show_logs' => false,

/*
|--------------------------------------------------------------------------
| Enable Cancel Event On Success
|--------------------------------------------------------------------------
|
| If the enable_cancel_event_on_success is set to "true", the cancel event will be triggered even if the payment is successful
|
*/
'enable_cancel_event_on_success' => true,

/*
|--------------------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions src/config/moamalat-pay.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@
*/
'show_logs' => false,

/*
|--------------------------------------------------------------------------
| Enable Cancel Event On Success
|--------------------------------------------------------------------------
|
| If the enable_cancel_event_on_success is set to "true", the cancel event will be triggered even if the payment is successful
|
*/
'enable_cancel_event_on_success' => true,


/*
|--------------------------------------------------------------------------
| Generate Secure Hash api
Expand Down
18 changes: 12 additions & 6 deletions src/views/pay.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
if (window.dispatchEvent) {
class MoamalataPay {
constructor(MID, TID, amount, merchantReference = "", debug = false) {
constructor(MID, TID, amount, merchantReference = "", enableCancelEventOnSuccess = true, debug = false) {
this.MID = MID;
this.TID = TID;
this.amount = amount;
this.merchantReference = merchantReference;
this.enableCancelEventOnSuccess = enableCancelEventOnSuccess;
this.debug = debug;
this.isCompleteCalled = false
}
Expand Down Expand Up @@ -58,6 +59,7 @@ class MoamalataPay {
this.log("Starting pay , mode => {{ config('moamalat-pay.production') ? 'produciton' : 'test' }}");
let parent_ = this;
this.isCompleteCalled = false;
const secureHashResponse = await this.fetchSecureHash();
Expand Down Expand Up @@ -93,11 +95,14 @@ class MoamalataPay {
});
},
cancelCallback: function() {
if (!this.isCompleteCalled) {
window.dispatchEvent(
new CustomEvent('moamalatCancel')
)
}
if (!parent_.enableCancelEventOnSuccess && this.isCompleteCalled) {
return;
}
window.dispatchEvent(
new CustomEvent('moamalatCancel')
)
parent_.log({
"status": "canceled"
});
Expand All @@ -114,6 +119,7 @@ class MoamalataPay {
"{{ config('moamalat-pay.terminal_id') }}",
0,
"",
"{{ config('moamalat-pay.enable_cancel_event_on_success') }}",
"{{ config('moamalat-pay.show_logs') }}",
)
Expand Down

0 comments on commit 05ac177

Please sign in to comment.