Exemple #1
0
class ClientTestCase(unittest.TestCase):
    def setUp(self):
        self.eway_client = EwayPaymentClient('87654321', config.REAL_TIME_CVN,
                                             False)

    def test_client(self):
        customer = Customer()
        customer.first_name = "Joe"
        customer.last_name = "Bloggs"
        customer.email = "*****@*****.**"
        customer.address = "123 Someplace Street, Somewhere ACT"
        customer.postcode = "2609"
        customer.invoice_description = "Testing"
        customer.invoice_reference = "INV120394"
        customer.country = "AU"

        credit_card = CreditCard()
        credit_card.holder_name = '%s %s' % (
            customer.first_name,
            customer.last_name,
        )
        credit_card.number = "4444333322221111"
        credit_card.expiry_month = 10
        credit_card.expiry_year = 12
        credit_card.verification_number = "123"
        credit_card.ip_address = "127.0.0.1"

        if customer.is_valid() and credit_card.is_valid():
            response = self.eway_client.authorize(Decimal("10.08"),
                                                  credit_card=credit_card,
                                                  customer=customer,
                                                  reference="123456")
            self.failUnless(response.success)
Exemple #2
0
def payment(request):
    # TODO logging needs to be added into here
    msg = ''
    form = ''
    t = loader.get_template('payment.html')
    message = ''
    if request.session.get("order_id", None):
        order = Order.objects.get(pk=request.session.get("order_id", 0))
    else:
        raise ValueError("Order not found")
    '''-------------------------------paypal-------------------------------------------------'''
    if request.POST.get("paypalcheckout.x", None):
        if float(order.getShippingCharged()) != 0:
            msgg = common.getResponse(order)

            if msgg['ACK'] == 'Success':

                return HttpResponseRedirect(
                    "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=%s&useraction=commit"
                    % msgg['TOKEN'])
            else:
                msg = msgg
                '''----------------------------------------------------------------------------------------'''

    elif request.POST:
        rp = request.POST.copy()
        if rp.get("editmyorder"):
            return HttpResponseRedirect("cart.html")
        form = CreditCardForm(rp)
        if form.is_valid():
            profile = order.user.get_profile()
            shipping = profile.shipping_set.all()
            billing = profile.billing_set.all()
            customer = Customer()
            names = form.cleaned_data.get("name")
            firstname = names[0]
            lastname = names[1]
            customer.first_name = firstname
            customer.last_name = lastname
            customer.email = billing[0].email
            customer.address = billing[0].address
            customer.postcode = billing[0].postcode
            customer.invoice_description = "Order from eastbourneart"
            customer.invoice_reference = order.getOrderNumber()
            customer.country = billing[0].country

            #op = CreditPayment()
            credit_card = CreditCard()
            #op.type = form.cleaned_data.get("type")
            credit_card.number = form.cleaned_data.get("number")
            credit_card.expiry_month = form.cleaned_data.get("expiryMonth")
            credit_card.expiry_year = form.cleaned_data.get("expiryYear")

            credit_card.holder_name = '%s %s' % (
                firstname,
                lastname,
            )
            credit_card.verification_number = form.cleaned_data.get("CVV")
            credit_card.ip_address = request.META["REMOTE_ADDR"]

            amount = float(order.total_charged)

            if customer.is_valid() and credit_card.is_valid():

                #17019375
                eway_client = EwayPaymentClient('17019375',
                                                config.REAL_TIME_CVN, True)
                response = eway_client.authorize(Decimal(str(amount)),
                                                 credit_card=credit_card,
                                                 customer=customer)
                if response.status.lower() == 'true':
                    order.status = OrderStatus.objects.get(
                        status__iexact=settings.TXT_SHOP_ORDER_STATUS_ORDERED)
                    order.save()
                    payment = True
                    t = loader.get_template('orderconfirmationemail.html')
                    d = {
                        "profile": profile,
                        "shipping": shipping[0],
                        "billing": billing[0],
                        'payment': payment
                    }
                    c = RequestContext(request, common.commonDict(d, request))
                    msg = t.render(c)
                    email = EmailMultiAlternatives(
                        'EASTBOURNEART Order Received - Order ' +
                        order.getOrderNumber(), msg,
                        '*****@*****.**',
                        ['*****@*****.**', order.user.email])
                    email.attach_alternative(msg, "text/html")
                    email.send()
                    '''---------------------------------------inventory----------------------------------------------'''
                    pos = order.productorder_set.all()
                    for x in pos:
                        if x.product.inventory:
                            x.product.inventory -= x.quantity
                            x.product.save()
                            if x.product.inventory <= x.product.maximum_quantity_wholesale:
                                t = loader.get_template('productinshort.html')
                                c = RequestContext(request,
                                                   {'product': x.product})
                                msg = t.render(c)
                                send_mail(
                                    'EASTBOURNEART Product In Short - Product '
                                    + x.product.title,
                                    msg,
                                    '*****@*****.**', [
                                        '*****@*****.**',
                                        '*****@*****.**'
                                    ],
                                    fail_silently=False)
                    '''----------------------------------------------------------------------------------------------'''
                    '''coupon =  request.session.get('coupon')
                    coupons = Coupon.objects.all()
                    for x in coupons:
                        r = x if x.checkCode(coupon) else None'''
                    #if r:
                    #r.addUsed(coupon)
                    # send_mail('EASTBOURNEART Order Received - Order '+ order.getOrderNumber(), msg, '*****@*****.**', [order.user.email], fail_silently=False)
                    request.session["order_id"] = None
                    request.session['coupon'] = ''
                    return HttpResponseRedirect("success%s.html" % order.id)
                else:
                    message = response.error

            else:
                return HttpResponse("ERROR: %s" %
                                    "Please supply all required infomation")
    else:
        form = CreditCardForm()
    country = request.session.get("shippingcountry", None)
    postcode = request.session.get("shippingpostcode", None)
    weight = order.getTotalWeight()
    try:
        if country.strip().lower() == "australia":
            price = postAustralia(getBoxes(order), getBoxWeight(order),
                                  postcode, order.getTotal())
        else:
            price = postInternational(getBoxes(order), getBoxWeight(order),
                                      postcode, country, order.getTotal())
        if not price:
            price = "?"
        price = 0.00 if price == 'free' else price
    except Exception, e:
        price = "?"
Exemple #3
0
 def setUp(self):
     self.eway_client = EwayPaymentClient('87654321',
                                          config.REAL_TIME_CVN,
                                          False)
Exemple #4
0
class ClientTestCase(unittest.TestCase):
    def setUp(self):
        self.eway_client = EwayPaymentClient('87654321',
                                             config.REAL_TIME_CVN,
                                             False)
    
    def get_data(self):
        """
        Test the eWAY auth complete functionality.
        """
        customer = Customer()
        customer.first_name = "Joe"
        customer.last_name = "Bloggs"
        customer.email = "*****@*****.**"
        customer.address = "35 rue de la fédération, Somewhere ACT".decode('utf-8')
        customer.postcode = "2609"
        customer.invoice_description = "Testing"
        customer.invoice_reference = "INV120394"
        customer.country = "AU"

        credit_card = CreditCard()
        credit_card.holder_name = '%s %s' % (customer.first_name, customer.last_name,)
        credit_card.number = "4444333322221111" 
        credit_card.expiry_month = 10
        credit_card.expiry_year = 12
        credit_card.verification_number = "123"
        credit_card.ip_address = "127.0.0.1"
        
        return [customer, credit_card]
    
    def test_payment(self):
        """
        Test the eWAY payment functionality.
        """
        customer, credit_card = self.get_data()

        if customer.is_valid() and credit_card.is_valid():
            response = self.eway_client.payment(
                Decimal("10.08"), 
                credit_card=credit_card, 
                customer=customer, 
                reference="123456"
            )
            self.failUnless(response.success)
            self.failUnlessEqual('Honour With Identification(Test CVN Gateway)', response.get_message())
            self.failUnlessEqual('08', response.get_code(), 'Response code should be 08')

    def test_authorisation_complete(self):
        """
        Test the eWAY auth complete functionality.
        
        @author: Alex Hayes <*****@*****.**> 
        """
        customer, credit_card = self.get_data()

        if customer.is_valid() and credit_card.is_valid():
            amount = Decimal("10.00")
            
            response = self.eway_client.authorisation(
                amount, 
                credit_card=credit_card, 
                customer=customer, 
                reference="123456"
            )
            self.failUnless(response.success)
            self.failUnlessEqual('Transaction Approved(Test CVN Gateway)', response.get_message())
            self.failUnlessEqual('00', response.get_code(), 'Response code should be 00')
            
            response = self.eway_client.complete(
                amount,
                10000000 # eWAY's test transaction number - response.transaction_number, 
            )
            self.failUnless(response.success)
            """
            In the following note the lack of CVN, according to eWAY this is because there is no CVN gateway for auth or void.
            """
            self.failUnlessEqual('Transaction Approved(Test Gateway)', response.get_message())
            self.failUnlessEqual('00', response.get_code(), 'Response code should be 00')
        
    def test_authorisation_void(self):
        """
        Test the eWAY auth void functionality.
        
        @author: Alex Hayes <*****@*****.**> 
        """
        customer, credit_card = self.get_data()

        if customer.is_valid() and credit_card.is_valid():
            amount = Decimal("10.00")
            
            response = self.eway_client.authorisation(
                amount, 
                credit_card=credit_card, 
                customer=customer, 
                reference="123456"
            )
            self.failUnless(response.success)
            self.failUnlessEqual('Transaction Approved(Test CVN Gateway)', response.get_message())
            self.failUnlessEqual('00', response.get_code(), 'Response code should be 00')
            
            response = self.eway_client.void(
                amount,
                10000000 # eWAY's test transaction number - response.transaction_number, 
            )
            self.failUnless(response.success)
            """
            In the following note the lack of CVN, according to eWAY this is because there is no CVN gateway for auth or void.
            """
            self.failUnlessEqual('Transaction Approved(Test Gateway)', response.get_message())
            self.failUnlessEqual('00', response.get_code(), 'Response code should be 00')
Exemple #5
0
 def setUp(self):
     self.eway_client = EwayPaymentClient('87654321', config.REAL_TIME_CVN,
                                          False)
Exemple #6
0
class ClientTestCase(unittest.TestCase):
    def setUp(self):
        self.eway_client = EwayPaymentClient('87654321', config.REAL_TIME_CVN,
                                             False)

    def get_data(self):
        """
        Test the eWAY auth complete functionality.
        """
        customer = Customer()
        customer.first_name = "Joe"
        customer.last_name = "Bloggs"
        customer.email = "*****@*****.**"
        customer.address = "35 rue de la fédération, Somewhere ACT".decode(
            'utf-8')
        customer.postcode = "2609"
        customer.invoice_description = "Testing"
        customer.invoice_reference = "INV120394"
        customer.country = "AU"

        credit_card = CreditCard()
        credit_card.holder_name = '%s %s' % (
            customer.first_name,
            customer.last_name,
        )
        credit_card.number = "4444333322221111"
        credit_card.expiry_month = 10
        credit_card.expiry_year = 12
        credit_card.verification_number = "123"
        credit_card.ip_address = "127.0.0.1"

        return [customer, credit_card]

    def test_payment(self):
        """
        Test the eWAY payment functionality.
        """
        customer, credit_card = self.get_data()

        if customer.is_valid() and credit_card.is_valid():
            response = self.eway_client.payment(Decimal("10.08"),
                                                credit_card=credit_card,
                                                customer=customer,
                                                reference="123456")
            self.failUnless(response.success)
            self.failUnlessEqual(
                'Honour With Identification(Test CVN Gateway)',
                response.get_message())
            self.failUnlessEqual('08', response.get_code(),
                                 'Response code should be 08')

    def test_authorisation_complete(self):
        """
        Test the eWAY auth complete functionality.
        
        @author: Alex Hayes <*****@*****.**> 
        """
        customer, credit_card = self.get_data()

        if customer.is_valid() and credit_card.is_valid():
            amount = Decimal("10.00")

            response = self.eway_client.authorisation(amount,
                                                      credit_card=credit_card,
                                                      customer=customer,
                                                      reference="123456")
            self.failUnless(response.success)
            self.failUnlessEqual('Transaction Approved(Test CVN Gateway)',
                                 response.get_message())
            self.failUnlessEqual('00', response.get_code(),
                                 'Response code should be 00')

            response = self.eway_client.complete(
                amount,
                10000000  # eWAY's test transaction number - response.transaction_number, 
            )
            self.failUnless(response.success)
            """
            In the following note the lack of CVN, according to eWAY this is because there is no CVN gateway for auth or void.
            """
            self.failUnlessEqual('Transaction Approved(Test Gateway)',
                                 response.get_message())
            self.failUnlessEqual('00', response.get_code(),
                                 'Response code should be 00')

    def test_authorisation_void(self):
        """
        Test the eWAY auth void functionality.
        
        @author: Alex Hayes <*****@*****.**> 
        """
        customer, credit_card = self.get_data()

        if customer.is_valid() and credit_card.is_valid():
            amount = Decimal("10.00")

            response = self.eway_client.authorisation(amount,
                                                      credit_card=credit_card,
                                                      customer=customer,
                                                      reference="123456")
            self.failUnless(response.success)
            self.failUnlessEqual('Transaction Approved(Test CVN Gateway)',
                                 response.get_message())
            self.failUnlessEqual('00', response.get_code(),
                                 'Response code should be 00')

            response = self.eway_client.void(
                amount,
                10000000  # eWAY's test transaction number - response.transaction_number, 
            )
            self.failUnless(response.success)
            """
            In the following note the lack of CVN, according to eWAY this is because there is no CVN gateway for auth or void.
            """
            self.failUnlessEqual('Transaction Approved(Test Gateway)',
                                 response.get_message())
            self.failUnlessEqual('00', response.get_code(),
                                 'Response code should be 00')
Exemple #7
0
 def setUp(self):
     # please change to your eway client
     self.eway_client = EwayPaymentClient('91728933',
                                          config.REAL_TIME_CVN,
                                          False,
                                          refund_password='******')
Exemple #8
0
class ClientTestCase(unittest.TestCase):
    def setUp(self):
        # please change to your eway client
        self.eway_client = EwayPaymentClient('91728933',
                                             config.REAL_TIME_CVN,
                                             False,
                                             refund_password='******')

    def get_data(self):
        """
        Test the eWAY auth complete functionality.
        """
        customer = Customer()
        customer.first_name = "Joe"
        customer.last_name = "Bloggs"
        customer.email = "*****@*****.**"
        customer.address = "123 Someplace Street, Somewhere ACT"
        customer.postcode = "2609"
        customer.invoice_description = "Testing"
        customer.invoice_reference = "INV120394"
        customer.country = "AU"

        credit_card = CreditCard()
        credit_card.holder_name = '%s %s' % (customer.first_name, customer.last_name,)
        credit_card.number = "4444333322221111"
        credit_card.expiry_month = 10
        credit_card.expiry_year = 15
        credit_card.verification_number = "123"
        credit_card.ip_address = "127.0.0.1"

        return [customer, credit_card]

    def test_refund(self):
        """
        Test the eWAY payment functionality.
        """
        customer, credit_card = self.get_data()

        # step 1, make a payment

        response = self.eway_client.payment(
            Decimal("10.08"),
            credit_card=credit_card,
            customer=customer,
            reference="123456"
        )

        self.failUnless(response.success)
        self.assertIn('Honour With Identification', response.get_message())
        self.failUnlessEqual('08', response.get_code(), 'Response code should be 08')

        resp_refund = self.eway_client.refund(
            Decimal('10.08'),
            response.transaction_number
        )

        self.failUnless(resp_refund.success)
        self.assertIsNotNone(resp_refund.transaction_number)
        self.failUnlessEqual('00', resp_refund.get_code())

    def test_refund_multiple(self):
        """
        Test the eWAY payment functionality.
        """
        customer, credit_card = self.get_data()

        # step 1, make a payment

        response = self.eway_client.payment(
            Decimal("20"),
            credit_card=credit_card,
            customer=customer,
            reference="123456"
        )

        self.failUnless(response.success)

        # reminding: $20
        resp_refund = self.eway_client.refund(
            Decimal('10'),
            response.transaction_number)

        self.assertTrue(resp_refund.success)
        self.assertIsNotNone(resp_refund.transaction_number)

        # reminding: $10. this one should failed.
        resp_refund = self.eway_client.refund(
            Decimal('15'),
            response.transaction_number,
        )
        self.assertFalse(resp_refund.success)

        # reminding: $10
        resp_refund = self.eway_client.refund(
            Decimal('7'),
            response.transaction_number
        )

        self.assertTrue(resp_refund.success)

        # reminding: $3
        resp_refund = self.eway_client.refund(
            Decimal('3.01'),
            response.transaction_number
        )

        self.assertFalse(resp_refund.success)

        # reminding: $3
        resp_refund = self.eway_client.refund(
            Decimal('3.00'),
            response.transaction_number
        )

        self.assertTrue(resp_refund.success)