Skip to content
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

Initial payment form styling #152

Merged
merged 1 commit into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions assets/css/wc-payment-checkout.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.wc-payment-card-mounted {
border: 1px solid #ddd;
padding: 5px 7px;
background-color: #fff;
}
16 changes: 9 additions & 7 deletions assets/js/wc-payment-checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ jQuery( function() {
'use strict';

var stripe = new Stripe( wc_payment_config.publishableKey, {
stripeAccount: wc_payment_config.accountId
stripeAccount: wc_payment_config.accountId,
} );
var elements = stripe.elements();

// Create a card element.
var cardElement = elements.create( 'card', {
hidePostalCode: true
hidePostalCode: true,
classes: { base: 'wc-payment-card-mounted' },
} );

// Only attempt to mount the card element once that section of the page has loaded. We can use the updated_checkout
Expand All @@ -21,12 +22,13 @@ jQuery( function() {
} );

// Update the validation state based on the element's state.
cardElement.addEventListener( 'change', function(event) {
var displayError = document.getElementById( 'wc-payment-errors' );
if (event.error) {
displayError.textContent = event.error.message;
cardElement.addEventListener( 'change', function( event ) {
var displayError = jQuery( '#wc-payment-errors' );
if ( event.error ) {
displayError.html( '<ul class="woocommerce-error"><li /></ul>' )
.find( 'li' ).text( event.error.message );
} else {
displayError.textContent = '';
displayError.html( '' );
}
} );

Expand Down
16 changes: 12 additions & 4 deletions includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,21 @@ public function payment_fields() {
wp_localize_script( 'wc-payment-checkout', 'wc_payment_config', $js_config );
wp_enqueue_script( 'wc-payment-checkout' );

wp_enqueue_style(
'wc-payment-checkout',
plugins_url( 'assets/css/wc-payment-checkout.css', WCPAY_PLUGIN_FILE ),
array(),
filemtime( WCPAY_ABSPATH . 'assets/css/wc-payment-checkout.css' )
RadoslavGeorgiev marked this conversation as resolved.
Show resolved Hide resolved
);

// Output the form HTML.
// TODO: Style this up. Formatting, escaping double line breaks etc.
?>
<p><?php echo wp_kses_post( $this->get_description() ); ?></p>
<div id="wc-payment-card-element"></div>
<div id="wc-payment-errors" role="alert"></div>
<input id="wc-payment-method" type="hidden" name="wc-payment-method" />
<fieldset>
<div id="wc-payment-card-element" class="form-row"></div>
<div id="wc-payment-errors" role="alert"></div>
<input id="wc-payment-method" type="hidden" name="wc-payment-method" />
</fieldset>
<?php
}

Expand Down