How to use the @paypal/sdk-constants/src.SDK_QUERY_KEYS.INTENT function in @paypal/sdk-constants

To help you get started, we’ve selected a few @paypal/sdk-constants examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github paypal / paypal-sdk-client / src / api.js View on Github external
if (!clientID) {
        throw new Error(`Client ID not passed`);
    }

    if (!order) {
        throw new Error(`Expected order details to be passed`);
    }

    const currency = getCurrency();
    const intent = getIntent();
    const merchantID = getMerchantID();

    order = { ...order };

    if (order.intent && order.intent.toLowerCase() !== intent) {
        throw new Error(`Unexpected intent: ${ order.intent } passed to order.create. Please ensure you are passing /sdk/js?${ SDK_QUERY_KEYS.INTENT }=${ order.intent.toLowerCase() } in the paypal script tag.`);
    }

    // $FlowFixMe
    order = { ...order, intent: intent.toUpperCase() };

    order.purchase_units = order.purchase_units.map(unit => {
        if (unit.amount.currency_code && unit.amount.currency_code !== currency) {
            throw new Error(`Unexpected currency: ${ unit.amount.currency_code } passed to order.create. Please ensure you are passing /sdk/js?${ SDK_QUERY_KEYS.CURRENCY }=${ unit.amount.currency_code } in the paypal script tag.`);
        }

        let payee = unit.payee;

        if (payee) {
            if (!merchantID) {
                throw new Error(`Pass ${ SDK_QUERY_KEYS.MERCHANT_ID }=XYZ in the paypal script tag. Pass ${ SDK_QUERY_KEYS.MERCHANT_ID }=${ UNKNOWN } if you do not have access to the merchant id`);
            }
github paypal / paypal-smart-payment-buttons / src / button / props / createOrder.js View on Github external
const create = (data) => {
    
        let order : Object = { ...data };
    
        if (order.intent && order.intent.toLowerCase() !== intent) {
            throw new Error(`Unexpected intent: ${ order.intent } passed to order.create. Please ensure you are passing /sdk/js?${ SDK_QUERY_KEYS.INTENT }=${ order.intent.toLowerCase() } in the paypal script tag.`);
        }

        order = { ...order, intent: intent.toUpperCase() };
    
        order.purchase_units = order.purchase_units.map(unit => {
            if (unit.amount.currency_code && unit.amount.currency_code !== currency) {
                throw new Error(`Unexpected currency: ${ unit.amount.currency_code } passed to order.create. Please ensure you are passing /sdk/js?${ SDK_QUERY_KEYS.CURRENCY }=${ unit.amount.currency_code } in the paypal script tag.`);
            }

            let payee = unit.payee;
    
            if (payee && merchantID && merchantID.length) {
                if (!merchantID[0]) {
                    throw new Error(`Pass ${ SDK_QUERY_KEYS.MERCHANT_ID }=XYZ in the paypal script tag.`);
                }
github paypal / paypal-sdk-client / src / script.js View on Github external
export function getIntent() : $Values {
    return getSDKQueryParam(SDK_QUERY_KEYS.INTENT, DEFAULT_INTENT);
}
github paypal / paypal-smart-payment-buttons / src / button / props / onApprove.js View on Github external
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);
    });
github paypal / paypal-smart-payment-buttons / src / button / orders.js View on Github external
]).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];

        if (!actualMerchantID) {
            throw new Error(`Could not determine correct merchant id`);
        }

        if (!payeeMerchantID) {
            throw new Error(`No payee found in transaction. Expected ${ actualMerchantID }`);
        }
github paypal / paypal-smart-payment-buttons / src / orders.js View on Github external
}).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)) {
            if (returnUrl && returnUrl.indexOf(ERROR_URL) !== 0) {
                throw new Error(`Return url is forbidden for smart payment button integration.`);
            }

            if (cancelUrl && cancelUrl.indexOf(ERROR_URL) !== 0) {
                throw new Error(`Cancel url is forbidden for smart payment button integration.`);
            }
        }
    });