mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-25 22:37:18 +10:00
Change transaction.js process to match alias (SCA version)
This commit is contained in:
parent
3a9f1960c6
commit
4cb1af5703
2 changed files with 42 additions and 13 deletions
|
|
@ -4,7 +4,8 @@ import { types as sdkTypes } from './sdkLoader';
|
|||
import { nightsBetween } from '../util/dates';
|
||||
import {
|
||||
TRANSITION_ACCEPT,
|
||||
TRANSITION_REQUEST,
|
||||
TRANSITION_CONFIRM_PAYMENT,
|
||||
TRANSITION_REQUEST_PAYMENT,
|
||||
TX_TRANSITION_ACTOR_CUSTOMER,
|
||||
TX_TRANSITION_ACTOR_PROVIDER,
|
||||
} from '../util/transaction';
|
||||
|
|
@ -143,7 +144,7 @@ export const createTxTransition = options => {
|
|||
return {
|
||||
createdAt: new Date(Date.UTC(2017, 4, 1)),
|
||||
by: TX_TRANSITION_ACTOR_CUSTOMER,
|
||||
transition: TRANSITION_REQUEST,
|
||||
transition: TRANSITION_REQUEST_PAYMENT,
|
||||
...options,
|
||||
};
|
||||
};
|
||||
|
|
@ -164,7 +165,12 @@ export const createTransaction = options => {
|
|||
createTxTransition({
|
||||
createdAt: new Date(Date.UTC(2017, 4, 1)),
|
||||
by: TX_TRANSITION_ACTOR_CUSTOMER,
|
||||
transition: TRANSITION_REQUEST,
|
||||
transition: TRANSITION_REQUEST_PAYMENT,
|
||||
}),
|
||||
createTxTransition({
|
||||
createdAt: new Date(Date.UTC(2017, 4, 1, 0, 0, 1)),
|
||||
by: TX_TRANSITION_ACTOR_CUSTOMER,
|
||||
transition: TRANSITION_CONFIRM_PAYMENT,
|
||||
}),
|
||||
createTxTransition({
|
||||
createdAt: new Date(Date.UTC(2017, 5, 1)),
|
||||
|
|
|
|||
|
|
@ -10,13 +10,24 @@ import { ensureTransaction } from './data';
|
|||
*/
|
||||
|
||||
// When a customer makes a booking to a listing, a transaction is
|
||||
// created with the initial request transition.
|
||||
export const TRANSITION_REQUEST = 'transition/request';
|
||||
// created with the initial request-payment transition.
|
||||
// At this transition a PaymentIntent is created by Marketplace API.
|
||||
// After this transition, the actual payment must be made on client-side directly to Stripe.
|
||||
export const TRANSITION_REQUEST_PAYMENT = 'transition/request-payment';
|
||||
|
||||
// A customer can also initiate a transaction with an enquiry, and
|
||||
// then transition that with a request.
|
||||
export const TRANSITION_ENQUIRE = 'transition/enquire';
|
||||
export const TRANSITION_REQUEST_AFTER_ENQUIRY = 'transition/request-after-enquiry';
|
||||
export const TRANSITION_REQUEST_PAYMENT_AFTER_ENQUIRY = 'transition/request-payment-after-enquiry';
|
||||
|
||||
// Stripe SDK might need to ask 3D security from customer, in a separate front-end step.
|
||||
// Therefore we need to make another transition to Marketplace API,
|
||||
// to tell that the payment is confirmed.
|
||||
export const TRANSITION_CONFIRM_PAYMENT = 'transition/confirm-payment';
|
||||
|
||||
// If the payment is not confirmed in the time limit set in transaction process (by default 15min)
|
||||
// the transaction will expire automatically.
|
||||
export const TRANSITION_EXPIRE_PAYMENT = 'transition/expire-payment';
|
||||
|
||||
// When the provider accepts or declines a transaction from the
|
||||
// SalePage, it is transitioned with the accept or decline transition.
|
||||
|
|
@ -73,6 +84,8 @@ export const TX_TRANSITION_ACTORS = [
|
|||
*/
|
||||
const STATE_INITIAL = 'initial';
|
||||
const STATE_ENQUIRY = 'enquiry';
|
||||
const STATE_PENDING_PAYMENT = 'pending-payment';
|
||||
const STATE_PAYMENT_EXPIRED = 'payment-expired';
|
||||
const STATE_PREAUTHORIZED = 'preauthorized';
|
||||
const STATE_DECLINED = 'declined';
|
||||
const STATE_ACCEPTED = 'accepted';
|
||||
|
|
@ -105,15 +118,23 @@ const stateDescription = {
|
|||
[STATE_INITIAL]: {
|
||||
on: {
|
||||
[TRANSITION_ENQUIRE]: STATE_ENQUIRY,
|
||||
[TRANSITION_REQUEST]: STATE_PREAUTHORIZED,
|
||||
[TRANSITION_REQUEST_PAYMENT]: STATE_PENDING_PAYMENT,
|
||||
},
|
||||
},
|
||||
[STATE_ENQUIRY]: {
|
||||
on: {
|
||||
[TRANSITION_REQUEST_AFTER_ENQUIRY]: STATE_PREAUTHORIZED,
|
||||
[TRANSITION_REQUEST_PAYMENT_AFTER_ENQUIRY]: STATE_PENDING_PAYMENT,
|
||||
},
|
||||
},
|
||||
|
||||
[STATE_PENDING_PAYMENT]: {
|
||||
on: {
|
||||
[TRANSITION_EXPIRE_PAYMENT]: STATE_PAYMENT_EXPIRED,
|
||||
[TRANSITION_CONFIRM_PAYMENT]: STATE_PREAUTHORIZED,
|
||||
},
|
||||
},
|
||||
|
||||
[STATE_PAYMENT_EXPIRED]: {},
|
||||
[STATE_PREAUTHORIZED]: {
|
||||
on: {
|
||||
[TRANSITION_DECLINE]: STATE_DECLINED,
|
||||
|
|
@ -199,12 +220,15 @@ export const transitionsToRequested = getTransitionsToState(STATE_PREAUTHORIZED)
|
|||
|
||||
const txLastTransition = tx => ensureTransaction(tx).attributes.lastTransition;
|
||||
|
||||
// DEPRECATED: use txIsDelivered instead
|
||||
export const txIsCompleted = tx => txLastTransition(tx) === TRANSITION_COMPLETE;
|
||||
|
||||
export const txIsEnquired = tx =>
|
||||
getTransitionsToState(STATE_ENQUIRY).includes(txLastTransition(tx));
|
||||
|
||||
export const txIsPaymentPending = tx =>
|
||||
getTransitionsToState(STATE_PENDING_PAYMENT).includes(txLastTransition(tx));
|
||||
|
||||
export const txIsPaymentExpired = tx =>
|
||||
getTransitionsToState(STATE_PAYMENT_EXPIRED).includes(txLastTransition(tx));
|
||||
|
||||
// Note: state name used in Marketplace API docs (and here) is actually preauthorized
|
||||
// However, word "requested" is used in many places so that we decided to keep it.
|
||||
export const txIsRequested = tx =>
|
||||
|
|
@ -277,10 +301,9 @@ export const isRelevantPastTransition = transition => {
|
|||
TRANSITION_ACCEPT,
|
||||
TRANSITION_CANCEL,
|
||||
TRANSITION_COMPLETE,
|
||||
TRANSITION_CONFIRM_PAYMENT,
|
||||
TRANSITION_DECLINE,
|
||||
TRANSITION_EXPIRE,
|
||||
TRANSITION_REQUEST,
|
||||
TRANSITION_REQUEST_AFTER_ENQUIRY,
|
||||
TRANSITION_REVIEW_1_BY_CUSTOMER,
|
||||
TRANSITION_REVIEW_1_BY_PROVIDER,
|
||||
TRANSITION_REVIEW_2_BY_CUSTOMER,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue