-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46ce282
commit 9934802
Showing
13 changed files
with
724 additions
and
57 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BeycanPress\CryptoPay\GravityForms\Gateways; | ||
|
||
// @phpcs:disable Generic.Files.InlineHTML | ||
// @phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps | ||
|
||
use BeycanPress\CryptoPayLite\Payment; | ||
|
||
class CryptoPayLite extends AbstractGateway | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
// @phpcs:ignore | ||
public $type = 'cryptopay-lite'; | ||
|
||
/** | ||
* @param array<mixed> $properties | ||
*/ | ||
public function __construct(array $properties = []) | ||
{ | ||
parent::__construct($properties); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function get_form_editor_field_title(): string | ||
{ | ||
return esc_attr__('CryptoPay Lite', 'gf-cryptopay'); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function get_form_editor_field_description(): string | ||
{ | ||
return esc_attr__('Adds cryptocurrency payments to your form.', 'gf-cryptopay'); | ||
} | ||
|
||
/** | ||
* @param int $formId | ||
* @return string | ||
*/ | ||
public function run(int $formId): string | ||
{ | ||
return (new Payment('gravityforms'))->html(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
;(($) => { | ||
$(document).ready(() => { | ||
let startedApp; | ||
let oldAmount = 0; | ||
const currency = gf_cryptopay_vars.currency; | ||
const submitButton = gf_cryptopay_vars.submitButton; | ||
const fieldInputId = gf_cryptopay_vars.fieldInputId; | ||
|
||
$(".gform_body [aria-required='true']").each(function() { | ||
$(this).attr('required', true); | ||
}); | ||
|
||
const paymentCompleted = async (ctx, formId) => { | ||
const form = $('#gform_' + formId); | ||
const helpers = window.cpHelpers || window.cplHelpers; | ||
const txHash = ctx.transaction.hash || ctx.transaction.id; | ||
|
||
console.log(ctx) | ||
// Modal yapısına geçilecek ve manuel olarak required alan kontrolü yapılacak | ||
// Create temporary payment completed record | ||
// Submit form | ||
// entry'ler ile transactionlar ilişkilendirilecek, | ||
// eğer bir kullanıcıya ve form id'sine ait tx varsa ödeme yapılmıştır sayılacak | ||
// ve entry oluşturulduğunda tx ile ilişkilendirilecek | ||
// eğer yoksa ödeme yapılması zorunlu olacak | ||
helpers.closePopup(); | ||
await helpers.sleep(100); | ||
helpers.successPopup('Payment completed successfully!').then(() => { | ||
$('.overlay').remove(); | ||
startedApp.store.payment.$reset(); | ||
$('#cryptopay, #cryptopay-lite').remove(); | ||
|
||
// scroll to form | ||
const wrapperOffset = $('.gform_wrapper').offset().top; | ||
$('html, body').animate({scrollTop: wrapperOffset}, 1000); | ||
|
||
// set tx hash to hidden input | ||
$('#' + fieldInputId).val(txHash); | ||
$('#' + fieldInputId).closest('.gfield').hide(); | ||
|
||
// submit form | ||
form.find('#custom-submit-placeholder').append(submitButton); | ||
form.submit(); | ||
}); | ||
} | ||
|
||
gform?.addFilter('gform_product_total', function (amount, formId) { | ||
if (amount !== oldAmount) { | ||
oldAmount = amount; | ||
if (window.CryptoPayApp) { | ||
CryptoPayApp.events.add('confirmationCompleted', async (ctx) => { | ||
paymentCompleted(ctx, formId); | ||
}, 'gravity_forms'); | ||
if (!startedApp) { | ||
startedApp = window.CryptoPayApp.start({ | ||
amount, | ||
currency, | ||
}, { formId }); | ||
} else { | ||
startedApp.reStart({ | ||
amount, | ||
currency, | ||
}, { formId }) | ||
} | ||
} else if (window.CryptoPayLiteApp) { | ||
CryptoPayLiteApp.events.add('confirmationCompleted', async (ctx) => { | ||
paymentCompleted(ctx, formId); | ||
}, 'gravity_forms'); | ||
if (!startedApp) { | ||
startedApp = window.CryptoPayLiteApp.start({ | ||
amount, | ||
currency, | ||
}, { formId }); | ||
} else { | ||
startedApp.reStart({ | ||
amount, | ||
currency, | ||
}, { formId }) | ||
} | ||
} | ||
} | ||
return amount; | ||
}); | ||
}); | ||
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.