Skip to content

Commit

Permalink
fix: Add stripeSelectedPaymentMethod to payment_selected click event
Browse files Browse the repository at this point in the history
  • Loading branch information
julianajlk committed Apr 15, 2024
1 parent b60c260 commit 7fa34ad
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/payment/checkout/Checkout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ class Checkout extends React.Component {
this.props.submitPayment({ method: 'stripe', ...formData });
};

handleSubmitStripeButtonClick = () => {
handleSubmitStripeButtonClick = (stripeSelectedPaymentMethod) => {
sendTrackEvent(
'edx.bi.ecommerce.basket.payment_selected',
{
type: 'click',
category: 'checkout',
paymentMethod: 'Credit Card - Stripe',
paymentMethod: stripeSelectedPaymentMethod === 'affirm' ? 'Affirm - Stripe' : 'Credit Card - Stripe',
checkoutType: 'client_side',
stripeEnabled: this.props.enableStripePaymentProcessor,
},
Expand Down
6 changes: 4 additions & 2 deletions src/payment/checkout/payment-form/PlaceOrderButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { injectIntl, FormattedMessage } from '@edx/frontend-platform/i18n';
import { StatefulButton } from '@openedx/paragon';

const PlaceOrderButton = ({
showLoadingButton, onSubmitButtonClick, disabled, isProcessing,
showLoadingButton, onSubmitButtonClick, stripeSelectedPaymentMethod, disabled, isProcessing,
}) => {
let submitButtonState = 'default';
// istanbul ignore if
Expand All @@ -26,7 +26,7 @@ const PlaceOrderButton = ({
size="lg"
block
state={submitButtonState}
onClick={onSubmitButtonClick}
onClick={() => onSubmitButtonClick(stripeSelectedPaymentMethod)}
labels={{
default: (
<FormattedMessage
Expand All @@ -52,13 +52,15 @@ const PlaceOrderButton = ({

PlaceOrderButton.propTypes = {
onSubmitButtonClick: PropTypes.func.isRequired,
stripeSelectedPaymentMethod: PropTypes.string,
showLoadingButton: PropTypes.bool,
disabled: PropTypes.bool,
isProcessing: PropTypes.bool,
};

PlaceOrderButton.defaultProps = {
showLoadingButton: false,
stripeSelectedPaymentMethod: null,
disabled: false,
isProcessing: false,
};
Expand Down
11 changes: 6 additions & 5 deletions src/payment/checkout/payment-form/StripePaymentForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const StripePaymentForm = ({
isSubscription,
paymentDataSelector,
}) => {
// Check payment type before submitting since BNPL requires state/zip code and Afterpay requires a shipping address.
// This is also used for analytics on "Place Order" click event.
const [stripeSelectedPaymentMethod, setStripeSelectedPaymentMethod] = useState(null);
const stripe = useStripe();
const elements = useElements();
const context = useContext(AppContext);
Expand All @@ -54,9 +57,6 @@ const StripePaymentForm = ({
const [firstErrorId, setfirstErrorId] = useState(false);
const [shouldFocusFirstError, setshouldFocusFirstError] = useState(false);

// Check payment type before submitting since BNPL requires state/zip code and Afterpay requires a shipping address
let stripePaymentMethodType;

const checkoutDetails = useSelector(paymentDataSelector);
const {
enableStripePaymentProcessor,
Expand Down Expand Up @@ -148,13 +148,13 @@ const StripePaymentForm = ({
}

onSubmitPayment({
skus, elements, stripe, context, values, stripePaymentMethodType,
skus, elements, stripe, context, values, stripeSelectedPaymentMethod,
});
};

const handleStripeElementOnChange = (event) => {
if (event.value) {
stripePaymentMethodType = event.value.type;
setStripeSelectedPaymentMethod(event.value.type);
}
};

Expand Down Expand Up @@ -227,6 +227,7 @@ const StripePaymentForm = ({
) : (
<PlaceOrderButton
onSubmitButtonClick={onSubmitButtonClick}
stripeSelectedPaymentMethod={stripeSelectedPaymentMethod}
showLoadingButton={showLoadingButton}
disabled={submitting}
isProcessing={isProcessing}
Expand Down
4 changes: 2 additions & 2 deletions src/payment/payment-methods/stripe/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ensureConfig(['ECOMMERCE_BASE_URL', 'STRIPE_RESPONSE_URL'], 'Stripe API service'
export default async function checkout(
basket,
{
skus, elements, stripe, context, values, stripePaymentMethodType,
skus, elements, stripe, context, values, stripeSelectedPaymentMethod,
},
setLocation = href => { global.location.href = href; }, // HACK: allow tests to mock setting location
) {
Expand All @@ -36,7 +36,7 @@ export default async function checkout(
} = values;

let shippingAddress;
if (stripePaymentMethodType === 'afterpay_clearpay') {
if (stripeSelectedPaymentMethod === 'afterpay_clearpay') {
shippingAddress = {
address: {
city,
Expand Down

0 comments on commit 7fa34ad

Please sign in to comment.