-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(payment): PAYPAL-4867 POC of headless wallet buttons
- Loading branch information
Showing
38 changed files
with
1,493 additions
and
9 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { createTimeout } from '@bigcommerce/request-sender'; | ||
|
||
export { createCheckoutHeadlessButtonInitializer } from '../checkout-buttons'; |
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,53 @@ | ||
import { createAction, createErrorAction, ThunkAction } from '@bigcommerce/data-store'; | ||
import { Observable, Observer } from 'rxjs'; | ||
|
||
import { RequestOptions } from '@bigcommerce/checkout-sdk/payment-integration-api'; | ||
|
||
import { InternalCheckoutSelectors } from '../checkout'; | ||
import { cachableAction } from '../common/data-store'; | ||
import ActionOptions from '../common/data-store/action-options'; | ||
import { MissingDataError, MissingDataErrorType } from '../common/error/errors'; | ||
|
||
import { CartActionType, LoadCartAction } from './cart-actions'; | ||
import CartRequestSender from './cart-request-sender'; | ||
|
||
export default class CartActionCreator { | ||
constructor(private _cartRequestSender: CartRequestSender) {} | ||
|
||
@cachableAction | ||
loadCardEntity( | ||
cartId: string, | ||
options?: RequestOptions & ActionOptions, | ||
): ThunkAction<LoadCartAction, InternalCheckoutSelectors> { | ||
return (store) => { | ||
return Observable.create((observer: Observer<LoadCartAction>) => { | ||
const state = store.getState(); | ||
const jwtToken = state.config.getStorefrontJwtToken(); | ||
|
||
if (!jwtToken) { | ||
throw new MissingDataError(MissingDataErrorType.MissingPaymentToken); | ||
} | ||
|
||
observer.next(createAction(CartActionType.LoadCartRequested, undefined)); | ||
|
||
this._cartRequestSender | ||
.loadCardEntity(cartId, { | ||
headers: { | ||
Authorization: `Bearer ${jwtToken}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
...options, | ||
}) | ||
.then((response) => { | ||
observer.next( | ||
createAction(CartActionType.LoadCartSucceeded, response.body), | ||
); | ||
observer.complete(); | ||
}) | ||
.catch((response) => { | ||
observer.error(createErrorAction(CartActionType.LoadCartFailed, response)); | ||
}); | ||
}); | ||
}; | ||
} | ||
} |
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,26 @@ | ||
import { Action } from '@bigcommerce/data-store'; | ||
|
||
import Cart from './cart'; | ||
|
||
export enum CartActionType { | ||
LoadCartRequested = 'LOAD_CART_REQUESTED', | ||
LoadCartSucceeded = 'LOAD_CART_SUCCEEDED', | ||
LoadCartFailed = 'LOAD_CART_FAILED', | ||
} | ||
|
||
export type LoadCartAction = | ||
| LoadCartRequestedAction | ||
| LoadCartSucceededAction | ||
| LoadCartFailedAction; | ||
|
||
export interface LoadCartRequestedAction extends Action { | ||
type: CartActionType.LoadCartRequested; | ||
} | ||
|
||
export interface LoadCartSucceededAction extends Action<Cart> { | ||
type: CartActionType.LoadCartSucceeded; | ||
} | ||
|
||
export interface LoadCartFailedAction extends Action<Error> { | ||
type: CartActionType.LoadCartFailed; | ||
} |
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
2 changes: 2 additions & 0 deletions
2
packages/core/src/checkout-buttons/checkout-button-initializer-options.ts
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export default interface CheckoutButtonInitializerOptions { | ||
host?: string; | ||
locale?: string; | ||
storefrontJwtToken?: string; | ||
siteLink?: string; | ||
} |
Oops, something went wrong.