mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-27 09:13:14 +10:00
Add initiate order after enquiry
If enquired transaction is avalable transition it to prequthorized on checkout page.
This commit is contained in:
parent
7cc30ee3ef
commit
bbac34a0e5
2 changed files with 59 additions and 4 deletions
|
|
@ -2,7 +2,7 @@ import pick from 'lodash/pick';
|
|||
import config from '../../config';
|
||||
import { denormalisedResponseEntities } from '../../util/data';
|
||||
import { storableError } from '../../util/errors';
|
||||
import { TRANSITION_REQUEST } from '../../util/types';
|
||||
import { TRANSITION_REQUEST, TRANSITION_REQUEST_AFTER_ENQUIRY } from '../../util/types';
|
||||
import * as log from '../../util/log';
|
||||
import { fetchCurrentUserHasOrdersSuccess } from '../../ducks/user.duck';
|
||||
|
||||
|
|
@ -146,6 +146,43 @@ export const initiateOrder = (orderParams, initialMessage) => (dispatch, getStat
|
|||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Initiate an order after an enquiry. Transitions previously created transaction.
|
||||
*/
|
||||
export const initiateOrderAfterEnquiry = (transactionId, orderParams) => (
|
||||
dispatch,
|
||||
getState,
|
||||
sdk
|
||||
) => {
|
||||
dispatch(initiateOrderRequest());
|
||||
|
||||
const bodyParams = {
|
||||
id: transactionId,
|
||||
transition: TRANSITION_REQUEST_AFTER_ENQUIRY,
|
||||
params: orderParams,
|
||||
};
|
||||
|
||||
return sdk.transactions
|
||||
.transition(bodyParams)
|
||||
.then(response => {
|
||||
const orderId = response.data.data.id;
|
||||
dispatch(initiateOrderSuccess(orderId));
|
||||
dispatch(fetchCurrentUserHasOrdersSuccess(true));
|
||||
// set initialMessageSuccess to true to unify promise handling with initiateOrder
|
||||
return Promise.resolve({ orderId, initialMessageSuccess: true });
|
||||
})
|
||||
.catch(e => {
|
||||
dispatch(initiateOrderError(storableError(e)));
|
||||
log.error(e, 'initiate-order-failed', {
|
||||
transactionId: transactionId.uuid,
|
||||
listingId: orderParams.listingId.uuid,
|
||||
bookingStart: orderParams.bookingStart,
|
||||
bookingEnd: orderParams.bookingEnd,
|
||||
});
|
||||
throw e;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Initiate the speculative transaction with the given booking details
|
||||
*
|
||||
|
|
|
|||
|
|
@ -30,7 +30,12 @@ import {
|
|||
} from '../../components';
|
||||
import { StripePaymentForm } from '../../forms';
|
||||
import { isScrollingDisabled } from '../../ducks/UI.duck';
|
||||
import { initiateOrder, setInitialValues, speculateTransaction } from './CheckoutPage.duck';
|
||||
import {
|
||||
initiateOrder,
|
||||
initiateOrderAfterEnquiry,
|
||||
setInitialValues,
|
||||
speculateTransaction,
|
||||
} from './CheckoutPage.duck';
|
||||
import config from '../../config';
|
||||
|
||||
import { storeData, storedData, clearData } from './CheckoutPageSessionHelpers';
|
||||
|
|
@ -139,7 +144,14 @@ export class CheckoutPageComponent extends Component {
|
|||
|
||||
const cardToken = values.token;
|
||||
const initialMessage = values.message;
|
||||
const { history, sendOrderRequest, speculatedTransaction, dispatch } = this.props;
|
||||
const {
|
||||
history,
|
||||
sendOrderRequest,
|
||||
sendOrderRequestAfterEnquiry,
|
||||
speculatedTransaction,
|
||||
enquiredTransaction,
|
||||
dispatch,
|
||||
} = this.props;
|
||||
|
||||
// Create order aka transaction
|
||||
// NOTE: if unit type is line-item/units, quantity needs to be added.
|
||||
|
|
@ -151,7 +163,11 @@ export class CheckoutPageComponent extends Component {
|
|||
bookingEnd: speculatedTransaction.booking.attributes.end,
|
||||
};
|
||||
|
||||
sendOrderRequest(requestParams, initialMessage)
|
||||
const initiateRequest = enquiredTransaction
|
||||
? sendOrderRequestAfterEnquiry(enquiredTransaction.id, requestParams)
|
||||
: sendOrderRequest(requestParams, initialMessage);
|
||||
|
||||
initiateRequest
|
||||
.then(values => {
|
||||
const { orderId, initialMessageSuccess } = values;
|
||||
this.setState({ submitting: false });
|
||||
|
|
@ -538,6 +554,8 @@ const mapStateToProps = state => {
|
|||
const mapDispatchToProps = dispatch => ({
|
||||
dispatch,
|
||||
sendOrderRequest: (params, initialMessage) => dispatch(initiateOrder(params, initialMessage)),
|
||||
sendOrderRequestAfterEnquiry: (transactionId, params) =>
|
||||
dispatch(initiateOrderAfterEnquiry(transactionId, params)),
|
||||
fetchSpeculatedTransaction: params => dispatch(speculateTransaction(params)),
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue