-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keep old payment form around for now
- Loading branch information
1 parent
e779b6f
commit b105031
Showing
5 changed files
with
392 additions
and
0 deletions.
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 |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
use craft\commerce\stripe\responses\CheckoutSessionResponse; | ||
use craft\commerce\stripe\responses\PaymentIntentResponse; | ||
use craft\commerce\stripe\web\assets\elementsform\ElementsFormAsset; | ||
use craft\commerce\stripe\web\assets\intentsform\IntentsFormAsset; | ||
use craft\elements\User; | ||
use craft\helpers\Json; | ||
use craft\helpers\StringHelper; | ||
|
@@ -81,6 +82,54 @@ public function showPaymentFormSubmitButton(): bool | |
return false; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getOldPaymentFormHtml(array $params): ?string | ||
{ | ||
$defaults = [ | ||
'gateway' => $this, | ||
'paymentForm' => $this->getPaymentFormModel(), | ||
'scenario' => 'payment', | ||
'handle' => $this->handle, | ||
]; | ||
|
||
$params = array_merge($defaults, $params); | ||
|
||
// If there's no order passed, add the current cart if we're not messing around in backend. | ||
if (!isset($params['order']) && !Craft::$app->getRequest()->getIsCpRequest()) { | ||
if ($cart = Commerce::getInstance()->getCarts()->getCart()) { | ||
$billingAddress = $cart->getBillingAddress(); | ||
|
||
/** @var User|CustomerBehavior|null $user */ | ||
$user = $cart->getCustomer(); | ||
Check failure on line 105 in src/gateways/PaymentIntents.php GitHub Actions / ci / Code Quality / PHPStan / PHPStan
|
||
if (!$billingAddress && $user) { | ||
$billingAddress = $user->getPrimaryBillingAddress(); | ||
} | ||
} | ||
} else { | ||
$billingAddress = $params['order']->getBillingAddress(); | ||
} | ||
|
||
if ($billingAddress) { | ||
$params['billingAddress'] = $billingAddress; | ||
} | ||
|
||
$view = Craft::$app->getView(); | ||
|
||
$previousMode = $view->getTemplateMode(); | ||
$view->setTemplateMode(View::TEMPLATE_MODE_CP); | ||
|
||
$view->registerScript('', View::POS_END, ['src' => 'https://js.stripe.com/v3/']); // we need this to load at end of body | ||
$view->registerAssetBundle(IntentsFormAsset::class); | ||
|
||
$html = $view->renderTemplate('commerce-stripe/paymentForms/oldIntentsForm', $params); | ||
|
||
$view->setTemplateMode($previousMode); | ||
|
||
return $html; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
|
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,108 @@ | ||
{% set paymentFormNamespace = handle|commercePaymentFormNamespace %} | ||
<div class="stripe-payment-intents-form" | ||
data-payment-form-namespace="{{ paymentFormNamespace }}" | ||
data-publishablekey="{{ parseEnv(gateway.getPublishableKey()) }}" | ||
{% if clientSecret is defined %}data-client-secret="{{clientSecret}}" {% endif %} | ||
{% if scenario is defined %}data-scenario="{{scenario}}" {% endif %} | ||
> | ||
|
||
<div class="payment-form-fields hidden"> | ||
{% namespace paymentFormNamespace %} | ||
{% import "_includes/forms" as forms %} | ||
|
||
<fieldset class="card-holder"> | ||
<legend>{{ 'Card Holder'|t('commerce') }}</legend> | ||
|
||
<div class="md:flex md:-mx-4"> | ||
<!-- Card Holder Name --> | ||
<div class="md:w-1/2 md:mx-4 my-2"> | ||
{{ forms.text({ | ||
name: 'firstName', | ||
maxlength: 70, | ||
placeholder: "First Name"|t('commerce'), | ||
autocomplete: false, | ||
class: 'card-holder-first-name'~(paymentForm.getErrors('firstName') ? ' error'), | ||
|
||
required: true, | ||
}) }} | ||
</div> | ||
|
||
<div class="md:w-1/2 md:mx-4 my-2"> | ||
{{ forms.text({ | ||
name: 'lastName', | ||
maxlength: 70, | ||
placeholder: "Last Name"|t('commerce'), | ||
autocomplete: false, | ||
class: 'card-holder-last-name'~(paymentForm.getErrors('lastName') ? ' error'), | ||
|
||
required: true, | ||
}) }} | ||
</div> | ||
</div> | ||
|
||
{% set errors = [] %} | ||
{% for attributeKey in ['firstName', 'lastName'] %} | ||
{% set errors = errors|merge(paymentForm.getErrors(attributeKey)) %} | ||
{% endfor %} | ||
|
||
{{ forms.errorList(errors) }} | ||
</fieldset> | ||
|
||
<!-- Card Number --> | ||
<fieldset class="card-data"> | ||
<legend>{{ 'Card'|t('commerce') }}</legend> | ||
|
||
<div> | ||
<div> | ||
{{ forms.text({ | ||
name: 'number', | ||
maxlength: 19, | ||
placeholder: "Card Number"|t('commerce'), | ||
autocomplete: false, | ||
class: 'card-number'~(paymentForm.getErrors('number') ? ' error'), | ||
|
||
}) }} | ||
|
||
</div> | ||
|
||
<div> | ||
{{ forms.text({ | ||
class: 'card-expiry'~(paymentForm.getErrors('month') or paymentForm.getErrors('year') ? ' error'), | ||
type: 'text', | ||
name: 'expiry', | ||
placeholder: "MM"|t('commerce')~' / '~"YYYY"|t('commerce'), | ||
|
||
}) }} | ||
|
||
{{ forms.text({ | ||
type: 'tel', | ||
name: 'cvv', | ||
placeholder: "CVV"|t('commerce'), | ||
class: 'card-cvc'~(paymentForm.getErrors('cvv') ? ' error'), | ||
|
||
}) }} | ||
</div> | ||
</div> | ||
|
||
{% set errors = [] %} | ||
{% for attributeKey in ['number', 'month', 'year', 'cvv'] %} | ||
{% set errors = errors|merge(paymentForm.getErrors(attributeKey)) %} | ||
{% endfor %} | ||
|
||
{{ forms.errorList(errors) }} | ||
|
||
</fieldset> | ||
{% endnamespace %} | ||
</div> | ||
|
||
<div class="card-errors" role="alert"></div> | ||
{% if billingAddress is defined %} | ||
<div class="stripe-address hidden"> | ||
<input type="hidden" name="stripe-line1" value="{{ billingAddress.addressLine1 }}" /> | ||
<input type="hidden" name="stripe-postal-code" value="{{ billingAddress.getPostalCode() }}" /> | ||
<input type="hidden" name="stripe-city" value="{{ billingAddress.getLocality() }}" /> | ||
<input type="hidden" name="stripe-country" value="{{ billingAddress.getCountryCode() }}" /> | ||
<input type="hidden" name="stripe-state" value="{{ billingAddress.getAdministrativeArea() }}" /> | ||
</div> | ||
{% endif %} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/** | ||
* @link https://craftcms.com/ | ||
* @copyright Copyright (c) Pixel & Tonic, Inc. | ||
* @license MIT | ||
*/ | ||
|
||
namespace craft\commerce\stripe\web\assets\intentsform; | ||
|
||
use yii\web\AssetBundle; | ||
use yii\web\JqueryAsset; | ||
|
||
/** | ||
* Asset bundle for the Payment Form | ||
*/ | ||
class IntentsFormAsset extends AssetBundle | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function init() | ||
{ | ||
$this->sourcePath = __DIR__; | ||
|
||
$this->css = [ | ||
'css/paymentForm.css', | ||
]; | ||
|
||
$this->js = [ | ||
'js/paymentForm.js', | ||
]; | ||
|
||
$this->depends = [ | ||
JqueryAsset::class, | ||
]; | ||
|
||
parent::init(); | ||
} | ||
} |
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,3 @@ | ||
.stripe-payment-intents-form { | ||
width: 310px; | ||
} |
Oops, something went wrong.