Add type of user as form data to be received on wc process payment request

This commit is contained in:
Emili Castells Guasch 2024-05-01 17:01:15 +02:00
parent c80f58abcf
commit 8a9dd52bd0
2 changed files with 13 additions and 7 deletions

View file

@ -646,7 +646,7 @@ class AxoManager {
return {
fields: fields,
styles: this.remove_keys_with_empty_string(this.axoConfig.style_options)
styles: this.delete_keys_with_empty_string(this.axoConfig.style_options)
}
}
@ -697,6 +697,9 @@ class AxoManager {
formData.set(key, data[key]);
});
// Set type of user (Ryan) to be received on WC gateway process payment request.
formData.set('fastlane_member', true);
fetch(wc_checkout_params.checkout_url, { // TODO: maybe create a new endpoint to process_payment.
method: "POST",
body: formData
@ -747,13 +750,13 @@ class AxoManager {
return this.axoConfig?.widgets?.email === 'use_widget';
}
remove_keys_with_empty_string = (obj) => {
delete_keys_with_empty_string = (obj) => {
for(let key of Object.keys(obj)){
if (obj[key] === ''){
delete obj[key];
}
else if (typeof obj[key] === 'object'){
obj[key] = this.remove_keys_with_empty_string(obj[key]);
obj[key] = this.delete_keys_with_empty_string(obj[key]);
if (Object.keys(obj[key]).length === 0 ) delete obj[key];
}
}

View file

@ -208,10 +208,13 @@ class AxoGateway extends WC_Payment_Gateway {
public function process_payment( $order_id ) {
$wc_order = wc_get_order( $order_id );
$payment_method_title = __( 'Credit Card (via Fastlane by PayPal)', 'woocommerce-paypal-payments' );
$wc_order->set_payment_method_title( $payment_method_title );
$wc_order->save();
// phpcs:ignore WordPress.Security.NonceVerification.Missing
$fastlane_member = wc_clean( wp_unslash( $_POST['fastlane_member'] ?? '' ) );
if ( $fastlane_member ) {
$payment_method_title = __( 'Debit & Credit Cards (via Fastlane by PayPal)', 'woocommerce-paypal-payments' );
$wc_order->set_payment_method_title( $payment_method_title );
$wc_order->save();
}
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );