class AdaptiveTests(TestCase):
    def setUp(self):

        self.preapproval = Preapproval()
        self.preapproval.money = Money(100, "SEK")
        self.preapproval.save()
        self.preapproval = Preapproval.objects.all()[0]

        self.payment = Payment()
        self.payment.money = Money(100, "USD")
        self.payment.save()
        self.payment = Payment.objects.all()[0]

        george = Receiver(amount=10,
                          email=settings.settings.PAYPAL_EMAIL,
                          primary=False)
        allen = Receiver(amount=90,
                         email="*****@*****.**",
                         primary=True)
        self.recievers = ReceiverList([george, allen])

    @patch("paypaladaptive.api.endpoints.UrlRequest",
           MockUrlRequestPreapproval)
    def test_preapproval(self):
        MockUrlRequestPreapproval.preapproval = (
            classmethod(lambda cls: self.preapproval))
        self.assertTrue(self.preapproval.process())
        self.preapproval = Preapproval.objects.get(pk=self.preapproval.pk)
        self.assertNotEqual(self.preapproval.preapproval_key, "")
        self.assertEqual(self.preapproval.status, "created")

    @patch("paypaladaptive.api.endpoints.UrlRequest", MockUrlRequestPayment)
    def test_payment(self):
        MockUrlRequestPayment.payment = classmethod(lambda cls: self.payment)
        MockUrlRequestPayment.recievers = classmethod(
            lambda cls: self.recievers)
        self.assertTrue(self.payment.process(self.recievers))
        self.payment = Payment.objects.get(pk=self.payment.id)
        self.assertTrue(self.payment.status, "created")
        self.assertNotEqual(self.payment.pay_key, "")

    @patch("paypaladaptive.models.Payment.call")
    def test_payment_from_preapproval(self, mock_api_caller):
        """Make sure we can create payments from Preapprovals"""

        preapproval = PreapprovalFactory.create(status='approved')
        mock_api_caller.return_value = (True, FakePay())

        self.assertTrue(
            self.payment.process(self.recievers, preapproval=self.preapproval))
        self.assertEqual(self.payment.status, 'completed')
class AdaptiveTests(TestCase):

    def setUp(self):

        self.preapproval = Preapproval()
        self.preapproval.money = Money(100, "SEK")
        self.preapproval.save()
        self.preapproval = Preapproval.objects.all()[0]

        self.payment = Payment()
        self.payment.money = Money(100, "USD")
        self.payment.save()
        self.payment = Payment.objects.all()[0]

        george = Receiver(amount=10, email=settings.settings.PAYPAL_EMAIL,
                          primary=False)
        allen = Receiver(amount=90, email="*****@*****.**",
                         primary=True)
        self.recievers = ReceiverList([george, allen])

    @patch("paypaladaptive.api.endpoints.UrlRequest",
           MockUrlRequestPreapproval)
    def test_preapproval(self):
        MockUrlRequestPreapproval.preapproval = (
            classmethod(lambda cls: self.preapproval))
        self.assertTrue(self.preapproval.process())
        self.preapproval = Preapproval.objects.get(pk=self.preapproval.pk)
        self.assertNotEqual(self.preapproval.preapproval_key, "")
        self.assertEqual(self.preapproval.status, "created")

    @patch("paypaladaptive.api.endpoints.UrlRequest",
           MockUrlRequestPayment)
    def test_payment(self):
        MockUrlRequestPayment.payment = classmethod(lambda cls: self.payment)
        MockUrlRequestPayment.recievers = classmethod(
            lambda cls: self.recievers)
        self.assertTrue(self.payment.process(self.recievers))
        self.payment = Payment.objects.get(pk=self.payment.id)
        self.assertTrue(self.payment.status, "created")
        self.assertNotEqual(self.payment.pay_key, "")

    @patch("paypaladaptive.models.Payment.call")
    def test_payment_from_preapproval(self, mock_api_caller):
        """Make sure we can create payments from Preapprovals"""

        preapproval = PreapprovalFactory.create(status='approved')
        mock_api_caller.return_value = (True, FakePay())

        self.assertTrue(self.payment.process(self.recievers,
                                             preapproval=self.preapproval))
        self.assertEqual(self.payment.status, 'completed')
Exemple #3
0
def testpaypal(request):
  # from paypaladaptive.models import Preapproval
  # from money.Money import Money
  # preapproval = Preapproval()
  # preapproval.money = Money(2000, 'usd')
  # preapproval.save()
  # preapproval.process(next='/home/', displayMaxTotalAmount=True)
  # # Redirect the user to the next_url() value
  # redirect_url = preapproval.next_url()
  from paypaladaptive.models import Payment
  from paypaladaptive.api import ReceiverList, Receiver
  from money.Money import Money
  key = 'APP-80W284485P519543T'
  platform = Receiver(amount=100, email="*****@*****.**", primary=False)
  merchant = Receiver(amount=1900, email="*****@*****.**", primary=True)
  receivers = ReceiverList([platform, merchant])

  p = Payment()
  p.money=Money(2000, 'USD')
  p.save()
  p.process(receivers, preapproval_key=key)
  return HttpResponseRedirect('/pay/return/')
Exemple #4
0
class TestPaymentResponses(TestCase):
    def setUp(self):
        self.payment = Payment()
        self.payment.money = Money(100, "USD")
        self.payment.save()
        self.payment = Payment.objects.all()[0]

        george = Receiver(amount=10, email=settings.settings.PAYPAL_EMAIL,
                          primary=False)
        allen = Receiver(amount=90, email="*****@*****.**",
                         primary=True)
        self.receivers = ReceiverList([george, allen])

    @patch("paypaladaptive.api.endpoints.UrlRequest", MockPaymentRequest)
    def testPaymentExecStatusError(self):
        MockPaymentRequest._response = (
            u'{"responseEnvelope":'
            u'{"timestamp":"2013-06-14T07:29:00.573-07:00",'
            u'"ack":"Success",'
            u'"correlationId":"0a2a453266f0c",'
            u'"build":"6133763"},'
            u'"payKey":"AP-7YC11928U7484393G",'
            u'"paymentExecStatus":"ERROR",'
            u'"payErrorList":'
            u'{"payError":[{'
            u'"receiver":{'
            u'"amount":"2000",'
            u'"email":"*****@*****.**",'
            u'"primary":"true"},'
            u'"error":{'
            u'"errorId":"569059",'
            u'"domain":"PLATFORM",'
            u'"severity":"Error",'
            u'"category":"Application",'
            u'"message":"Instant payments can\'t be pending"}}]}}')

        res = self.payment.process(self.receivers)
        self.assertFalse(res)
        self.assertEqual(self.payment.status, 'error')
        self.assertEqual(
            self.payment.status_detail,
            u"Error 569059: Instant payments can\'t be pending")