-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for visa mobile (on-site) #85
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
94c6009
Visa Mobile redirected UI version
arti0090 d2094ed
Visa Mobile payment - API
arti0090 3c9af0e
Add tests and additional changes to make Visa Mobile API and UI
arti0090 f74b998
Remake the task as Visa Mobile On-site
arti0090 a5ce2f8
Validate UI and API value of mobile phone
arti0090 97b877f
Fixes after rebase
arti0090 b345603
Rebase, add final to test classes
arti0090 9e913de
Fix false-positive test regarding Visa Mobile, add additional validat…
arti0090 f2ef368
Add E2E test
arti0090 66715fe
Make validation great again :rocket:
arti0090 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import './img/hourglass.gif'; | ||
import './scss/style.scss'; | ||
import './js/_pay_by_link'; | ||
import './js/_visa_mobile'; | ||
import {CardForm} from "./js/card_form"; | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
if (!document.querySelector('[name="sylius_checkout_complete"]').querySelector('[data-tpay-card-holder-name]')) { | ||
return; | ||
} | ||
new CardForm('[name="sylius_checkout_complete"]'); | ||
}); |
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,79 @@ | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const MOBILE_PHONE_MIN_LENGTH = 7; | ||
const MOBILE_PHONE_MAX_LENGTH = 15; | ||
|
||
let form = document.querySelector('[name="sylius_checkout_complete"]'); | ||
let phoneNumber = form.querySelector('#sylius_checkout_complete_tpay_visa_mobile_phone_number'); | ||
|
||
if (null === phoneNumber) { | ||
return; | ||
} | ||
|
||
form.addEventListener('submit', (event) => { | ||
validateVisaMobilePhoneNumber(phoneNumber); | ||
|
||
const isValid = form.querySelectorAll('.sylius-validation-error').length === 0; | ||
|
||
if (!isValid) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
|
||
form.classList.remove('loading'); | ||
|
||
return; | ||
} | ||
|
||
|
||
form.submit(); | ||
}); | ||
|
||
function validateVisaMobilePhoneNumber(field) { | ||
let fieldLength = field.value.length; | ||
|
||
if (MOBILE_PHONE_MIN_LENGTH <= fieldLength && fieldLength <= MOBILE_PHONE_MAX_LENGTH) { | ||
clearErrors(phoneNumber); | ||
return; | ||
} | ||
|
||
if (fieldLength === 0) { | ||
addError(phoneNumber); | ||
return; | ||
} | ||
|
||
if (fieldLength < MOBILE_PHONE_MIN_LENGTH) { | ||
addError(phoneNumber, 'validationErrorMinLength'); | ||
return; | ||
} | ||
|
||
if (fieldLength > MOBILE_PHONE_MAX_LENGTH) { | ||
addError(phoneNumber, 'validationErrorMaxLength'); | ||
return; | ||
} | ||
|
||
addError(phoneNumber); | ||
} | ||
|
||
function clearErrors(field) { | ||
const tpayField = field.closest('[data-tpay-field]'); | ||
const errorContainer = tpayField.querySelector('[data-tpay-error-container]'); | ||
|
||
errorContainer.innerHTML = ''; | ||
} | ||
|
||
function addError(field, validationErrorName = 'validationErrorRequired') { | ||
const tpayField = field.closest('[data-tpay-field]'); | ||
const errorContainer = tpayField.querySelector('[data-tpay-error-container]'); | ||
|
||
errorContainer.innerHTML = createErrorElement(field, validationErrorName); | ||
} | ||
|
||
function createErrorElement(field, validationErrorName = 'validationErrorRequired') { | ||
const errorMessage = field.dataset[validationErrorName]; | ||
|
||
return ` | ||
<div class="ui red pointing label sylius-validation-error"> | ||
${errorMessage} | ||
</div> | ||
`; | ||
} | ||
}); |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\Api\Command; | ||
|
||
final class PayByVisaMobile | ||
{ | ||
public function __construct( | ||
public readonly int $paymentId, | ||
public readonly string $visaMobilePhoneNumber, | ||
) { | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\Api\Command; | ||
|
||
use CommerceWeavers\SyliusTpayPlugin\Model\PaymentDetails; | ||
use Sylius\Component\Core\Model\PaymentInterface; | ||
use Symfony\Component\Messenger\Attribute\AsMessageHandler; | ||
|
||
#[AsMessageHandler] | ||
final class PayByVisaMobileHandler extends AbstractPayByHandler | ||
{ | ||
public function __invoke(PayByVisaMobile $command): PayResult | ||
{ | ||
$payment = $this->findOr404($command->paymentId); | ||
|
||
$this->setTransactionData($payment); | ||
$this->createTransaction($payment); | ||
|
||
return $this->createResultFrom($payment, false); | ||
} | ||
|
||
private function setTransactionData(PaymentInterface $payment): void | ||
{ | ||
$paymentDetails = PaymentDetails::fromArray($payment->getDetails()); | ||
$paymentDetails->setVisaMobilePhoneNumber($paymentDetails->getVisaMobilePhoneNumber()); | ||
|
||
$payment->setDetails($paymentDetails->toArray()); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed. Should be removed