-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Payments: scaffold the checkout pending page, the 2nd attempt. (#23827)
* Implement a placeholder version of `<CheckoutPending>` component. * Register pending routes, `/checkout/thank-you/<site>/pending/:orderId` to the controller. * Update the route to include parsing `site` path parameter * Direct to different ending routes accordingly. * update `getSourcePaymentTransactionDetail()` as `getOrderTransaction()` * Dispatch `setOrderTransactionError` on error. * Granularize the routing rules of the pending checkout page. * `showErrorNotice()` need to be called after `page()`. Otherwise, the notice would be eliminated before showing. * Fix the case handling for the general API error. * Update the copy according to the copy review feedbacks. * Redirect users back to the plan page instead of the homepage in case of payment cancellation or technical errors.
- Loading branch information
Showing
5 changed files
with
160 additions
and
18 deletions.
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
client/my-sites/checkout/checkout-thank-you/pending.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/** @format */ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import page from 'page'; | ||
import { localize } from 'i18n-calypso'; | ||
import React, { PureComponent } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import { identity } from 'lodash'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { getOrderTransaction, getOrderTransactionError } from 'state/selectors'; | ||
import { ORDER_TRANSACTION_STATUS } from 'state/order-transactions/constants'; | ||
import { errorNotice } from 'state/notices/actions'; | ||
|
||
class CheckoutPending extends PureComponent { | ||
static propTypes = { | ||
orderId: PropTypes.number.isRequired, | ||
siteSlug: PropTypes.string.isRequired, | ||
transaction: PropTypes.object, | ||
error: PropTypes.object, | ||
errorNotice: PropTypes.func, | ||
localize: PropTypes.func, | ||
}; | ||
|
||
static defaultProps = { | ||
localize: identity, | ||
errorNotice: identity, | ||
}; | ||
|
||
componentWillReceiveProps( nextProps ) { | ||
const { transaction, error } = nextProps; | ||
const { translate, showErrorNotice, siteSlug } = this.props; | ||
|
||
const retryOnError = () => { | ||
page( `/checkout/${ siteSlug }` ); | ||
|
||
showErrorNotice( | ||
translate( "Sorry, we couldn't process your payment. Please try again later." ) | ||
); | ||
}; | ||
|
||
const planRoute = `/plans/my-plan/${ siteSlug }`; | ||
|
||
if ( transaction ) { | ||
const { processingStatus } = transaction; | ||
|
||
if ( ORDER_TRANSACTION_STATUS.SUCCESS === processingStatus ) { | ||
page( `/checkout/thank-you/${ siteSlug }` ); | ||
|
||
return; | ||
} | ||
|
||
// It is mostly because the user has cancelled the payment. | ||
// See the explanation in https://github.com/Automattic/wp-calypso/pull/23670#issuecomment-377186515 | ||
if ( ORDER_TRANSACTION_STATUS.FAILURE === processingStatus ) { | ||
// Bring the user back to the plan page in this case. | ||
page( planRoute ); | ||
|
||
return; | ||
} | ||
|
||
// or the processing status indicates that there was something wrong. | ||
if ( ORDER_TRANSACTION_STATUS.ERROR === processingStatus ) { | ||
// redirect users back to the checkout page so they can try again. | ||
retryOnError(); | ||
|
||
return; | ||
} | ||
|
||
// The API has responded a status string that we don't expect somehow. | ||
if ( ORDER_TRANSACTION_STATUS.UNKNOWN === processingStatus ) { | ||
// Redirect users back to the plan page so that they won't be stuck here. | ||
page( planRoute ); | ||
|
||
showErrorNotice( translate( 'Oops! Something went wrong. Please try again later.' ) ); | ||
|
||
return; | ||
} | ||
} | ||
|
||
// A HTTP error occurs. We use the same handling | ||
if ( error ) { | ||
retryOnError(); | ||
} | ||
} | ||
|
||
render() { | ||
const { orderId } = this.props; | ||
|
||
// TODO: | ||
// Replace this placeholder by the real one | ||
return ( | ||
<div> | ||
<p>Waiting for the payment result of { orderId }</p> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default connect( | ||
( state, props ) => ( { | ||
transaction: getOrderTransaction( state, props.orderId ), | ||
error: getOrderTransactionError( state, props.orderId ), | ||
} ), | ||
{ | ||
showErrorNotice: errorNotice, | ||
} | ||
)( localize( CheckoutPending ) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters