コード例 #1
0
    def test_non_200_response_raises_exception(self):
        response = self.create_mock_response(body='', status_code=500)

        with patch('requests.post') as post:
            post.return_value = response
            with self.assertRaises(express.PayPalError):
                express.set_txn(self.basket, self.methods, 'GBP', 'http://localhost:8000/success',
                                'http://localhost:8000/error')
コード例 #2
0
    def test_error_response_raises_exception(self):
        response_body = 'TIMESTAMP=2012%2d03%2d26T16%3a33%3a09Z&CORRELATIONID=3bea2076bb9c3&ACK=Failure&VERSION=0%2e000000&BUILD=2649250&L_ERRORCODE0=10002&L_SHORTMESSAGE0=Security%20error&L_LONGMESSAGE0=Security%20header%20is%20not%20valid&L_SEVERITYCODE0=Error'
        response = self.create_mock_response(response_body)

        with patch('requests.post') as post:
            post.return_value = response
            with self.assertRaises(express.PayPalError):
                express.set_txn(self.basket, self.methods, 'GBP', 'http://localhost:8000/success',
                                'http://localhost:8000/error')
コード例 #3
0
    def setUp(self):
        super(SuccessResponseTests, self).setUp()
        response_body = 'TOKEN=EC%2d6469953681606921P&TIMESTAMP=2012%2d03%2d26T17%3a19%3a38Z&CORRELATIONID=50a8d895e928f&ACK=Success&VERSION=60%2e0&BUILD=2649250'
        response = self.create_mock_response(response_body)

        with patch('requests.post') as post:
            post.return_value = response
            self.url = express.set_txn(self.basket, self.methods, 'GBP', 
                                       'http://localhost:8000/success',
                                       'http://localhost:8000/error')
コード例 #4
0
def get_paypal_url(basket, shipping_methods, user=None, shipping_address=None,
                   shipping_method=None, host=None, scheme='http'):
    """
    Return the URL for PayPal Express transaction.

    This involves registering the txn with PayPal to get a one-time
    URL.  If a shipping method and shipping address are passed, then these are
    given to PayPal directly - this is used within when using PayPal as a
    payment method.
    """
    currency = getattr(settings, 'PAYPAL_CURRENCY', 'GBP')
    if host is None:
        host = Site.objects.get_current().domain
    return_url = '%s://%s%s' % (scheme, host, reverse('paypal-success-response'))
    cancel_url = '%s://%s%s' % (scheme, host, reverse('paypal-cancel-response'))

    # URL for updating shipping methods - we only use this if we have a set of
    # shipping methods to choose between.
    update_url = None
    if shipping_methods:
        update_url = '%s://%s%s' % (scheme, host, reverse('paypal-shipping-options',
                                                        kwargs={'basket_id': basket.id}))

    # Pass a default billing address is there is one.  This means PayPal can
    # pre-fill the registration form.
    address = None
    if user:
        addresses = user.addresses.all().order_by('-is_default_for_billing')
        if len(addresses):
            address = addresses[0]

    return set_txn(basket=basket,
                   shipping_methods=shipping_methods,
                   currency=currency,
                   return_url=return_url,
                   cancel_url=cancel_url,
                   update_url=update_url,
                   action=_get_payment_action(),
                   shipping_method=shipping_method,
                   shipping_address=shipping_address,
                   user=user,
                   user_address=address)