Beispiel #1
0
 def test_charge_card_declined(self):
     card = get_card(**self.card_info)
     self.assertRaises(AuthorizeResponseError, charge_card,
                       70.02, card)
     self.assertRaises(AuthorizeResponseError, charge_card,
                       70.03, card)
     self.assertRaises(AuthorizeResponseError, charge_card,
                       70.05, card)
Beispiel #2
0
    def clean(self):
        cleaned_data = self.cleaned_data
        if cleaned_data.get("country") not in ["United States", "Canada"] and not self.instance.pk:
            region = cleaned_data.get("region")
            if region:
                cleaned_data["state"] = region
            else:
                raise ValidationError("State or region is required.")

        if not self.company:
            company_name = self.cleaned_data.get("company_name")
            msg = clean_company_name(company_name, None)
            if msg:
                self._errors["company_name"] = self.error_class([msg])
                raise ValidationError(msg)

        exp_date = self.cleaned_data.get("exp_date")
        try:
            month = exp_date.month
            year = exp_date.year
        except AttributeError:
            msg = "Invalid CC Expiration Date."
            self._errors["exp_Date"] = self.error_class([msg])
            raise ValidationError(msg)
        address = "%s %s" % (
            self.cleaned_data.get("address_line_one", ""),
            self.cleaned_data.get("address_line_two", ""),
        )
        try:
            card = get_card(
                self.cleaned_data.get("card_number"),
                self.cleaned_data.get("cvv"),
                month,
                year,
                self.cleaned_data.get("first_name"),
                self.cleaned_data.get("last_name"),
                address,
                self.cleaned_data.get("city"),
                self.cleaned_data.get("state"),
                self.cleaned_data.get("zip_code"),
                self.product.owner.companyprofile.authorize_net_login,
                self.product.owner.companyprofile.authorize_net_transaction_key,
                self.cleaned_data.get("country"),
            )
        except AuthorizeInvalidError, e:
            self._errors["card_number"] = self.error_class([e.message])
            raise ValidationError(e.message)
Beispiel #3
0
    def clean(self):
        cleaned_data = self.cleaned_data
        if (cleaned_data.get('country') not in ["United States", "Canada"]
                and not self.instance.pk):
            region = cleaned_data.get('region')
            if region:
                cleaned_data['state'] = region
            else:
                raise ValidationError('State or region is required.')

        if not self.company:
            company_name = self.cleaned_data.get('company_name')
            msg = clean_company_name(company_name, None)
            if msg:
                self._errors['company_name'] = self.error_class([msg])
                raise ValidationError(msg)

        exp_date = self.cleaned_data.get('exp_date')
        try:
            month = exp_date.month
            year = exp_date.year
        except AttributeError:
            msg = 'Invalid CC Expiration Date.'
            self._errors['exp_Date'] = self.error_class([msg])
            raise ValidationError(msg)
        address = "%s %s" % (self.cleaned_data.get('address_line_one', ''),
                             self.cleaned_data.get('address_line_two', ''))
        try:
            card = get_card(
                self.cleaned_data.get('card_number'),
                self.cleaned_data.get('cvv'), month, year,
                self.cleaned_data.get('first_name'),
                self.cleaned_data.get('last_name'), address,
                self.cleaned_data.get('city'), self.cleaned_data.get('state'),
                self.cleaned_data.get('zip_code'),
                self.product.owner.companyprofile.authorize_net_login, self.
                product.owner.companyprofile.authorize_net_transaction_key,
                self.cleaned_data.get('country'))
        except AuthorizeInvalidError, e:
            self._errors['card_number'] = self.error_class([e.message])
            raise ValidationError(e.message)
Beispiel #4
0
    def clean(self):
        cleaned_data = self.cleaned_data
        if (cleaned_data.get('country') not in ["United States", "Canada"]
                and not self.instance.pk):
            region = cleaned_data.get('region')
            if region:
                cleaned_data['state'] = region
            else:
                raise ValidationError('State or region is required.')

        if not self.company:
            company_name = self.cleaned_data.get('company_name')
            msg = clean_company_name(company_name, None)
            if msg:
                self._errors['company_name'] = self.error_class([msg])
                raise ValidationError(msg)

        exp_date = self.cleaned_data.get('exp_date')
        try:
            month = exp_date.month
            year = exp_date.year
        except AttributeError:
            msg = 'Invalid CC Expiration Date.'
            self._errors['exp_Date'] = self.error_class([msg])
            raise ValidationError(msg)
        address = "%s %s" % (self.cleaned_data.get('address_line_one', ''),
                             self.cleaned_data.get('address_line_two', ''))
        try:
            card = get_card(self.cleaned_data.get('card_number'),
                            self.cleaned_data.get('cvv'), month, year,
                            self.cleaned_data.get('first_name'),
                            self.cleaned_data.get('last_name'),
                            address, self.cleaned_data.get('city'),
                            self.cleaned_data.get('state'),
                            self.cleaned_data.get('zip_code'),
                            self.product.owner.companyprofile.authorize_net_login,
                            self.product.owner.companyprofile.authorize_net_transaction_key,
                            self.cleaned_data.get('country'))
        except AuthorizeInvalidError, e:
            self._errors['card_number'] = self.error_class([e.message])
            raise ValidationError(e.message)
Beispiel #5
0
 def test_charge_card_invalid_cvn(self):
     self.card_info['cvn'] = 901
     card = get_card(**self.card_info)
     self.assertRaises(AuthorizeResponseError, charge_card, 70.02, card)
Beispiel #6
0
 def test_charge_card_declined(self):
     card = get_card(**self.card_info)
     self.assertRaises(AuthorizeResponseError, charge_card, 70.02, card)
     self.assertRaises(AuthorizeResponseError, charge_card, 70.03, card)
     self.assertRaises(AuthorizeResponseError, charge_card, 70.05, card)
Beispiel #7
0
 def test_charge_card(self):
     card = get_card(**self.card_info)
     charge_card(random.randint(1, 5000), card)
Beispiel #8
0
 def test_get_card(self):
     get_card(**self.card_info)
Beispiel #9
0
 def test_charge_card_invalid_cvn(self):
     self.card_info['cvn'] = 901
     card = get_card(**self.card_info)
     self.assertRaises(AuthorizeResponseError, charge_card,
                       70.02, card)
Beispiel #10
0
 def test_charge_card(self):
     card = get_card(**self.card_info)
     charge_card(random.randint(1, 5000), card)
Beispiel #11
0
 def test_get_card(self):
     get_card(**self.card_info)
Beispiel #12
0
 def test_charge_card(self):
     card = get_card(**self.card_info)
     charge_card(1, card)