-
Notifications
You must be signed in to change notification settings - Fork 217
Moving OC card method logic to the new OC payment method class #4579
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
Changes from 83 commits
9109f75
27848e1
6dd474b
fc32555
bfa1738
074f9fb
73d97f4
a93ecb0
172e0ed
896e3d0
e29852a
12c5bba
bd021ae
52464b8
4c5faaa
bb83e47
0fd565e
d51e259
d515862
bbf9f22
db7a424
cc480ce
35c4062
799c5d6
d87a919
51c8994
683e94e
f4ddf11
ba19a5e
1e7c5c0
b3665a8
55c5fc3
467aef1
f86bdea
a494227
954eff8
79716e2
44973f1
a1062e9
aecd42a
e7e19b4
fb4c602
4cdbfac
ac88378
e1b568d
b8dcaca
eb23e83
c0b0db3
738b9e0
8167222
a492833
d725830
792cc4a
87c3d2c
0955ec9
b78fd40
099b665
712d0ff
e61cfeb
33f4486
d63de45
bd6e5c9
65eb3f1
ec23a93
805d633
26c2911
046375f
94e164a
ae1cb67
ce4817a
65ba94f
c28b903
a1281a0
be6a48c
f95015e
bf66fb1
0b78567
7feb8d9
2624188
4d60f51
11c628a
fa4bee1
3c5f37d
f58a3fe
6b129cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ class WC_Stripe_Payment_Methods { | |
const SEPA_DEBIT = 'sepa_debit'; | ||
const SOFORT = 'sofort'; | ||
const WECHAT_PAY = 'wechat_pay'; | ||
const OC = 'card'; // This is a special case for the Optimized Checkout | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: To avoid any ambiguity, should we set this to its own ID (eg: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried that, but it caused a lot of bugs (tried it again now and still couldn't do it). We still need some stuff from the card payment method class (even when inactive). That was the way I could make it as independent as possible. We can revisit this later |
||
|
||
// Express method constants | ||
const AMAZON_PAY = 'amazon_pay'; | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,119 @@ | ||||||||
<?php | ||||||||
if ( ! defined( 'ABSPATH' ) ) { | ||||||||
exit; | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* Class WC_Stripe_UPE_Payment_Method_OC | ||||||||
* | ||||||||
* This class represents the Stripe UPE payment method for the Optimized Checkout (OC) flow. | ||||||||
*/ | ||||||||
class WC_Stripe_UPE_Payment_Method_OC extends WC_Stripe_UPE_Payment_Method { | ||||||||
|
||||||||
const STRIPE_ID = WC_Stripe_Payment_Methods::OC; | ||||||||
|
||||||||
/** | ||||||||
* Constructor for the Optimized Checkout payment method (which renders all methods). | ||||||||
*/ | ||||||||
public function __construct() { | ||||||||
parent::__construct(); | ||||||||
$main_settings = WC_Stripe_Helper::get_stripe_settings(); | ||||||||
$is_stripe_enabled = ! empty( $main_settings['enabled'] ) && 'yes' === $main_settings['enabled']; | ||||||||
|
||||||||
$this->enabled = $is_stripe_enabled && $this->oc_enabled ? 'yes' : 'no'; | ||||||||
$this->id = WC_Gateway_Stripe::ID; // Force the ID to be the same as the main payment gateway. | ||||||||
$this->stripe_id = self::STRIPE_ID; | ||||||||
$this->title = 'Stripe'; | ||||||||
$this->is_reusable = true; | ||||||||
$this->supports[] = 'subscriptions'; | ||||||||
$this->supports[] = 'tokenization'; | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* Returns payment method title | ||||||||
* | ||||||||
* @param stdClass|array|bool $payment_details Optional payment details from charge object. | ||||||||
* | ||||||||
* @return string | ||||||||
*/ | ||||||||
public function get_title( $payment_details = false ) { | ||||||||
// Wallet type | ||||||||
$wallet_type = $payment_details->card->wallet->type ?? null; | ||||||||
if ( $wallet_type ) { | ||||||||
return $this->get_card_wallet_type_title( $wallet_type ); | ||||||||
} | ||||||||
|
||||||||
if ( $payment_details ) { // Setting title for the order details page / thank you page. | ||||||||
$payment_method = WC_Stripe_UPE_Payment_Gateway::get_payment_method_instance( $payment_details->type ); | ||||||||
|
||||||||
// Avoid potential recursion by checking instance type. This fixes the title on pay for order confirmation page. | ||||||||
return $payment_method instanceof self ? parent::get_title() : $payment_method->get_title(); | ||||||||
} | ||||||||
|
||||||||
// Block checkout and pay for order (checkout) page. | ||||||||
if ( ( has_block( 'woocommerce/checkout' ) || ! empty( $_GET['pay_for_order'] ) ) && ! is_wc_endpoint_url( 'order-received' ) ) { // phpcs:ignore WordPress.Security.NonceVerification | ||||||||
return 'Stripe'; | ||||||||
wjrosa marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
} | ||||||||
|
||||||||
return parent::get_title(); | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* Returns true if the UPE method is available. | ||||||||
* | ||||||||
* @inheritDoc | ||||||||
*/ | ||||||||
public function is_available() { | ||||||||
return true; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we do something like
Suggested change
I see the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. Added it in f58a3fe. I didn't apply your suggestion directly due to linting. |
||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* Returns string representing payment method type | ||||||||
* to query to retrieve saved payment methods from Stripe. | ||||||||
* | ||||||||
* @inheritDoc | ||||||||
*/ | ||||||||
public function get_retrievable_type() { | ||||||||
return WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID; | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* Returns boolean dependent on whether capability | ||||||||
* for site account is enabled for payment method. | ||||||||
* | ||||||||
* @inheritDoc | ||||||||
*/ | ||||||||
public function is_capability_active() { | ||||||||
return true; | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* The Optimized Checkout method allows automatic capture. | ||||||||
* | ||||||||
* @inheritDoc | ||||||||
*/ | ||||||||
public function requires_automatic_capture() { | ||||||||
return false; | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* Returns testing credentials to be printed at checkout in test mode. | ||||||||
* | ||||||||
* @param bool $show_optimized_checkout_instruction Whether this is being called through the Optimized Checkout instructions method. Used to avoid an infinite loop call. | ||||||||
* @return string | ||||||||
*/ | ||||||||
public function get_testing_instructions( $show_optimized_checkout_instruction = false ) { | ||||||||
if ( ! $show_optimized_checkout_instruction ) { | ||||||||
return WC_Stripe_UPE_Payment_Gateway::get_testing_instructions_for_optimized_checkout(); | ||||||||
} | ||||||||
|
||||||||
return sprintf( | ||||||||
/* translators: 1) HTML strong open tag 2) HTML strong closing tag 3) HTML anchor open tag 2) HTML anchor closing tag */ | ||||||||
esc_html__( '%1$sTest mode:%2$s use the test VISA card 4242424242424242 with any expiry date and CVC. Other payment methods may redirect to a Stripe test page to authorize payment. More test card numbers are listed %3$shere%4$s.', 'woocommerce-gateway-stripe' ), | ||||||||
'<strong>', | ||||||||
'</strong>', | ||||||||
'<a href="https://docs.stripe.com/testing" target="_blank">', | ||||||||
'</a>' | ||||||||
); | ||||||||
} | ||||||||
} |
Uh oh!
There was an error while loading. Please reload this page.