Skip to content

Commit

Permalink
PR feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdharmesh committed Jan 30, 2024
1 parent 35e7f42 commit 9d3bc1f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
10 changes: 8 additions & 2 deletions assets/blocks/cash-app-pay/component-cash-app-pay.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export const ComponentCashAppPay = (props) => {
return;
}

(async () => {
async function setupIntegration(){
setIsLoaded(false);
try {
const paymentRequest = await createPaymentRequest(payments);
if (window.wcSquareCashAppPay) {
Expand Down Expand Up @@ -119,6 +120,10 @@ export const ComponentCashAppPay = (props) => {

// Place an Order.
onSubmit();
} else {
// Declined. Reset the nonce and re-initialize the Square Cash App Pay Button.
setPaymentNonce(null);
setupIntegration();
}
});

Expand All @@ -136,7 +141,8 @@ export const ComponentCashAppPay = (props) => {
console.error(e);
}
setIsLoaded(true);
})();
}
setupIntegration();

return () =>
(async () => {
Expand Down
6 changes: 6 additions & 0 deletions assets/js/frontend/wc-square-cash-app-pay.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ jQuery( document ).ready( ( $ ) => {
} else {
$( 'form.checkout' ).trigger('submit');
}
} else {
// Declined transaction. Unblock UI and re-build Cash App Pay.
if ( this.blockedForm ) {
this.blockedForm.unblock();
}
this.build_cash_app();
}
}

Expand Down
17 changes: 8 additions & 9 deletions includes/Gateway/Cash_App_Pay_Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected function enqueue_gateway_assets() {
$is_checkout = is_checkout() || ( function_exists( 'has_block' ) && has_block( 'woocommerce/checkout' ) );

// bail if not a checkout page or cash app pay is not enabled
if ( ! ( $is_checkout || $this->is_configured() ) ) {
if ( ! $is_checkout || ! $this->is_configured() ) {
return;
}

Expand Down Expand Up @@ -376,11 +376,13 @@ public function is_available() {
* @return boolean true if the gateway is properly configured
*/
public function is_configured() {
// Only available in the US
// Only available in the US and USD currency.
$base_location = wc_get_base_location();
$base_currency = get_woocommerce_currency();
$us_only = isset( $base_location['country'] ) && 'US' === $base_location['country'];
$usd_only = 'USD' === $base_currency;

return $this->is_enabled() && $us_only && $this->get_plugin()->get_settings_handler()->is_connected() && $this->get_plugin()->get_settings_handler()->get_location_id();
return $this->is_enabled() && $us_only && $usd_only && $this->get_plugin()->get_settings_handler()->is_connected() && $this->get_plugin()->get_settings_handler()->get_location_id();
}

/** Getter methods ************************************************************************************************/
Expand Down Expand Up @@ -626,13 +628,10 @@ protected function get_order_with_unique_transaction_ref( $order ) {
}

/**
* Returns the payment method image URL (if any) for the given $type, ie
* if $type is 'amex' a URL to the american express card icon will be
* returned. If $type is 'echeck', a URL to the echeck icon will be
* returned.
* Returns the payment method image URL.
*
* @since x.x.x
* @param string $type the payment method cc type or name
* @param string $type the payment method type or name
* @return string the image URL or null
*/
public function get_payment_method_image_url( $type = '' ) {
Expand All @@ -646,7 +645,7 @@ public function get_payment_method_image_url( $type = '' ) {
*/
$image_extension = apply_filters( 'wc_payment_gateway_' . $this->get_id() . '_use_svg', true ) ? '.svg' : '.png';

// first, is the card image available within the plugin?
// first, is the image available within the plugin?
if ( is_readable( $this->get_plugin()->get_plugin_path() . '/assets/images/cash-app' . $image_extension ) ) {
return \WC_HTTPS::force_https_url( $this->get_plugin()->get_plugin_url() . '/assets/images/cash-app' . $image_extension );
}
Expand Down

0 comments on commit 9d3bc1f

Please sign in to comment.