Skip to content

Commit

Permalink
:submit selector instead of button
Browse files Browse the repository at this point in the history
add brand identification handler for customization
  • Loading branch information
ruskid committed Feb 5, 2017
1 parent bac5772 commit 2965f5c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions StripeForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ class StripeForm extends \yii\widgets\ActiveForm {
*/
public $brandContainerId = 'cc-brand';

/**
* Used if jquery payment validation is true. Called when card brand is identified
* @var JsExpression|string
*/
public $brandIdentificationHandler;

//Stripe constants
const NUMBER_ID = 'number';
const CVC_ID = 'cvc';
Expand Down Expand Up @@ -148,6 +154,12 @@ public function init() {
});
});';
}

if($this->applyJqueryPaymentValidation && !isset($this->cardValidationBrandHandler)){
$this->brandIdentificationHandler = 'function(cardType){
$("#' . $this->brandContainerId . '").text(cardType);
}';
}
}

/**
Expand Down Expand Up @@ -202,7 +214,7 @@ public function registerJqueryPaymentScripts() {
return this;
};
$("#' . $this->options['id'] . ' button").on("click", function(e) {
$("#' . $this->options['id'] . ' :submit").on("click", function(e) {
var $form = $("#' . $this->options['id'] . '");
var $number = $("input[data-stripe=' . self::NUMBER_ID . ']");
var $cvc = $("input[data-stripe=' . self::CVC_ID . ']");
Expand All @@ -211,7 +223,7 @@ public function registerJqueryPaymentScripts() {
var $year = $("input[data-stripe=' . self::YEAR_ID . ']");
var cardType = $.payment.cardType($number.val());
$("#' . $this->brandContainerId . '").text(cardType);
(' . $this->brandIdentificationHandler .')(cardType);
$number.toggleInputError(!$.payment.validateCardNumber($number.val()));
$cvc.toggleInputError(!$.payment.validateCardCVC($cvc.val(), cardType));
Expand Down

0 comments on commit 2965f5c

Please sign in to comment.