Exemple #1
0
def set_payment_options(client,
                        pay_key,
                        receiver_options,
                        display_options=None,
                        sender_options=None,
                        shipping_address_id=None,
                        initiating_entity=None,
                        extra={}):
    """Execute the SetPaymentOptions API call which will customize
    behavior of the payment procedure at PayPal.

    :param client: An instance of ``'pypal.Client'``
    :param pay_key: The PayPal token associated with the transaction
    :param sender_options: Dictionary containing sender customizations
    :param receiver_options: Dictionary containing receiver customizations
    :param display_options: Dictionary containing display customizations
    :param shipping_address_id: The PayPal identifier for the shipping
                                address to set.
    :param initiating_entity: Dictionary containing initiating entity
                              customizations.
    :param extra: Additional key-value arguments to send to PayPal
    """
    extra['payKey'] = pay_key
    set_nonempty_param(extra, 'initiatingEntity', initiating_entity)
    set_nonempty_param(extra, 'displayOptions', display_options)
    set_nonempty_param(extra, 'shippingAddressId', shipping_address_id)
    set_nonempty_param(extra, 'senderOptions', sender_options)
    set_nonempty_param(extra, 'receiverOptions', receiver_options)
    return call(client, 'SetPaymentOptions', extra)
Exemple #2
0
def pay(client,
        action_type,
        currency_code,
        cancel_url,
        return_url,
        ipn_callback_url,
        receivers=None,
        fees_payer=None,
        extra={}):
    """Execute the Pay API call which will prepare the payment procedure.
    Most importantly it will return a pay key which should be utilized in
    order to identify the transaction.

    :param client: An instance of ``'pypal.Client'``
    :param action_type: The payment action type
    :param currency_code: Which currency code to utilize in the transaction
    :param cancel_url: The URL which the end-user is sent to on
                       payment cancellation.
    :param return_url: The URL which the end-user is sent to on completed
                       payment, in all cases be it success or failure.
    :param ipn_callback_url: The URL which will receive the IPN notifications
                             related to this operation. The Adaptive Payment API
                             requires this to be explicitly set and does not
                             fallback on the default IPN URL for the
                             application.
    :param receivers: A list of the receivers of this transaction
    :param fees_payer: Who will pay the PayPal fees
    :param extra: Additional key-value arguments to send to PayPal
    """
    check_required(locals(), ('cancel_url', 'return_url', 'currency_code',
                              'action_type', 'receivers', 'ipn_callback_url'))

    if not currency.is_valid_code(currency_code):
        raise ValueError('Given currency code (%s) '
                         'is not supported' % currency_code)

    if action_type not in SUPPORTED_PAY_ACTIONS:
        raise ValueError('Given payment action (%s) is not any of the '
                         'supported types; %s' % (action_type,
                                                  SUPPORTED_PAY_ACTIONS))

    if fees_payer and fees_payer not in SUPPORTED_FEE_PAYERS:
        raise ValueError('Given value (%s) for the fees_payer argument '
                         'is not supported by PayPal' % fees_payer)

    if not isinstance(receivers, ReceiverList):
        if not isinstance(receivers, (list, tuple)):
            receivers = [receivers]
        receivers = ReceiverList(receivers)

    extra.update({'actionType': action_type,
                  'receiverList': { 'receiver': receivers },
                  'currencyCode': currency_code,
                  'cancelUrl': cancel_url,
                  'returnUrl': return_url})

    set_nonempty_param(extra, 'ipnNotificationUrl', ipn_callback_url)
    set_nonempty_param(extra, 'feesPayer', fees_payer)
    return call(client, 'Pay', extra)