Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
|};
export const DEFAULT_STYLE = {
LAYOUT: BUTTON_LAYOUT.VERTICAL,
COLOR: BUTTON_COLOR.GOLD,
SHAPE: BUTTON_SHAPE.RECT
};
export const DEFAULT_PROPS = {
LOCALE: {
country: COUNTRY.US,
lang: LANG.EN
},
COMMIT: COMMIT.TRUE,
VAULT: VAULT.FALSE,
INTENT: INTENT.CAPTURE,
ENV: ENV.PRODUCTION,
PLATFORM: PLATFORM.DESKTOP
};
// $FlowFixMe
export function normalizeButtonStyle(style : ButtonStyleInputs) : ButtonStyle {
if (!style) {
throw new Error(`Expected props.style to be set`);
}
const {
label,
layout = DEFAULT_STYLE.LAYOUT,
color = DEFAULT_STYLE.COLOR,
shape = DEFAULT_STYLE.SHAPE,
|};
export const DEFAULT_STYLE = {
LAYOUT: BUTTON_LAYOUT.VERTICAL,
COLOR: BUTTON_COLOR.GOLD,
SHAPE: BUTTON_SHAPE.RECT
};
export const DEFAULT_PROPS = {
LOCALE: {
country: COUNTRY.US,
lang: LANG.EN
},
COMMIT: COMMIT.TRUE,
VAULT: VAULT.FALSE,
INTENT: INTENT.CAPTURE,
ENV: ENV.PRODUCTION,
PLATFORM: PLATFORM.DESKTOP
};
// $FlowFixMe
export function normalizeButtonStyle(style : ButtonStyleInputs) : ButtonStyle {
if (!style) {
throw new Error(`Expected props.style to be set`);
}
const {
label,
layout = DEFAULT_STYLE.LAYOUT,
color = DEFAULT_STYLE.COLOR,
shape = DEFAULT_STYLE.SHAPE,
onError: (err) => {
throw err;
}
};
},
postRobot: {
on: () => ({ cancel: noop }),
once: () => cancelablePromise(ZalgoPromise.resolve()),
send: () => cancelablePromise(ZalgoPromise.resolve())
}
};
window.xprops = {
clientID: 'xyz123',
platform: PLATFORM.DESKTOP,
intent: INTENT.CAPTURE,
currency: CURRENCY.USD,
commit: true,
env: 'test',
buttonSessionID: uniqueID(),
createOrder: mockAsyncProp(() => {
return 'XXXXXXXXXX';
}),
style: {
},
locale: {
country: 'US',
lang: 'en'
},
onInit: mockAsyncProp(noop),
onApprove: mockAsyncProp(noop),
const execute = memoize(() => {
if (intent !== INTENT.CAPTURE) {
throw new Error(`Use ${ SDK_QUERY_KEYS.INTENT }=${ INTENT.CAPTURE } to use client-side capture`);
}
return executePayment(paymentID, payerID, { facilitatorAccessToken, buyerAccessToken, partnerAttributionID })
.finally(get.reset)
.finally(execute.reset)
.catch(handleProcessorError);
});
const capture = memoize(() => {
if (window.xprops.intent !== INTENT.CAPTURE) {
throw new Error(`Use ${ SDK_QUERY_KEYS.INTENT }=${ INTENT.CAPTURE } to use client-side capture`);
}
return captureOrder(orderID)
.catch(handleProcessorError)
.finally(get.reset);
});
const capture = memoize(() => {
if (intent !== INTENT.CAPTURE) {
throw new Error(`Use ${ SDK_QUERY_KEYS.INTENT }=${ INTENT.CAPTURE } to use client-side capture`);
}
return captureOrder(orderID, { facilitatorAccessToken, buyerAccessToken, partnerAttributionID, forceRestAPI })
.finally(get.reset)
.finally(capture.reset)
.catch(handleProcessorError);
});
const execute = memoize(() => {
if (intent !== INTENT.CAPTURE) {
throw new Error(`Use ${ SDK_QUERY_KEYS.INTENT }=${ INTENT.CAPTURE } to use client-side capture`);
}
return executePayment(paymentID, payerID, { facilitatorAccessToken, buyerAccessToken, partnerAttributionID })
.finally(get.reset)
.finally(execute.reset)
.catch(handleProcessorError);
});
const create = (data) => {
let payment : Object = { ...data };
const expectedIntent = (intent === INTENT.CAPTURE ? 'sale' : intent);
if (payment.intent && payment.intent !== expectedIntent) {
throw new Error(`Unexpected intent: ${ payment.intent } passed to order.create. Expected ${ expectedIntent }`);
}
payment = { ...payment, intent: expectedIntent };
payment.transactions = payment.transactions.map(transaction => {
if (transaction.amount.currency && transaction.amount.currency !== currency) {
throw new Error(`Unexpected currency: ${ transaction.amount.currency } passed to order.create. Please ensure you are passing /sdk/js?${ SDK_QUERY_KEYS.CURRENCY }=${ transaction.amount.currency } in the paypal script tag.`);
}
let payee = transaction.payee;
if (payee && merchantID && merchantID.length) {
if (!merchantID[0]) {
}).then(res => {
const cart = res.data.checkoutSession.cart;
const intent = (cart.intent.toLowerCase() === 'sale') ? INTENT.CAPTURE : cart.intent.toLowerCase();
const currency = cart.amounts && cart.amounts.total.currencyCode;
const returnUrl = cart.returnUrl && cart.returnUrl.href;
const cancelUrl = cart.cancelUrl && cart.cancelUrl.href;
const expectedIntent = window.xprops.intent;
const expectedCurrency = window.xprops.currency;
if (intent !== expectedIntent) {
throw new Error(`Expected intent from order api call to be ${ expectedIntent }, got ${ intent }. Please ensure you are passing ${ SDK_QUERY_KEYS.INTENT }=${ intent } to the sdk`);
}
if (currency && currency !== expectedCurrency) {
throw new Error(`Expected currency from order api call to be ${ expectedCurrency }, got ${ currency }. Please ensure you are passing ${ SDK_QUERY_KEYS.CURRENCY }=${ currency } to the sdk`);
}
if (isOrderID(orderID)) {
]).then(([ gql, payee ]) => {
const cart = gql.checkoutSession.cart;
const intent = (cart.intent.toLowerCase() === 'sale') ? INTENT.CAPTURE : cart.intent.toLowerCase();
const currency = cart.amounts && cart.amounts.total.currencyCode;
const expectedIntent = intent;
const expectedCurrency = currency;
if (intent !== expectedIntent) {
throw new Error(`Expected intent from order api call to be ${ expectedIntent }, got ${ intent }. Please ensure you are passing ${ SDK_QUERY_KEYS.INTENT }=${ intent } to the sdk`);
}
if (currency && currency !== expectedCurrency) {
throw new Error(`Expected currency from order api call to be ${ expectedCurrency }, got ${ currency }. Please ensure you are passing ${ SDK_QUERY_KEYS.CURRENCY }=${ currency } to the sdk`);
}
const payeeMerchantID = payee && payee.merchant && payee.merchant.id;
const actualMerchantID = merchantID && merchantID.length && merchantID[0];