Esempio n. 1
0
    def test_is_successful_errored(self):
        card = Card()
        card.status = "errored"
        payment = Payment()
        payment.card = card

        self.assertFalse(payment.is_successful())
Esempio n. 2
0
    def test_is_successful_declined(self):
        card = Card()
        card.status = "declined"
        payment = Payment(source='card')
        payment.card = card

        self.assertFalse(payment.is_successful())
Esempio n. 3
0
    def test_is_successful(self):
        card = Card()
        card.status = "processed"
        card_payment = CardPayment()
        card_payment.card = card

        self.assertTrue(card_payment.is_successful())
Esempio n. 4
0
    def __init__(self, source="card", data=None):

        if not data:
            return

        self.customer_id = int(data["customer_id"])
        self.date = parse(data["date"])

        total_amount = Decimal(data["amount"])
        self.fee = total_amount * PAYMENT_FEE_RATE
        self.amount = total_amount - self.fee

        if source == "card":
            card = Card()
            card.card_id = int(data["card_id"])
            card.status = data["card_status"]
            self.card = card
            self.payment_successful = self.card.status == "processed"
        elif source == "bank":
            bank_account = BankAccount()
            bank_account.bank_account_id = int(data["bank_account_id"])
            self.bank_account = bank_account
            self.payment_successful = True
        else:
            raise ValueError('Unsupported payment method')
Esempio n. 5
0
    def test_is_successful(self):
        card = Card()
        card.status = "processed"
        payment = Payment(source='card')
        payment.card = card

        self.assertTrue(payment.is_successful())
Esempio n. 6
0
    def test_is_successful_declined(self):
        card = Card()
        card.status = "declined"
        card_payment = CardPayment()
        card_payment.card = card

        self.assertFalse(card_payment.is_successful())
Esempio n. 7
0
 def __init__(self, data=None):
     if not data:
         return
     super(PaymentByCard, self).__init__(data)
     card = Card()
     card.card_id = int(data["card_id"])
     card.status = data["card_status"]
     self.card = card
 def __init__(self, data=None):
     if not data:
         return
     super(CardPayment, self).__init__(data)
     card = Card()
     card.card_id = int(data.get("card_id", None))
     card.status = data.get("card_status", None)
     self.card = card
Esempio n. 9
0
    def test_is_successful(self):
        card = Card()
        card.status = "processed"
        payment1 = Payment()
        payment1.card = card

        bank = Bank()
        bank.status = "processed"
        payment2 = Payment()
        payment2.bank = bank

        self.assertTrue(payment1.is_successful())
        self.assertTrue(payment2.is_successful())
Esempio n. 10
0
    def __init__(self, data=None):

        if not data:
            return

        self.customer_id = int(data["customer_id"])
        self.date = parse(data["date"])

        total_amount = Decimal(data["amount"])
        self.fee = total_amount * PAYMENT_FEE_RATE
        self.amount = total_amount - self.fee

        card = Card()
        card.card_id = int(data["card_id"])
        card.status = data["card_status"]
        self.card = card
Esempio n. 11
0
    def process_trx(self, data):
        self.customer_id = int(data.get("customer_id"))
        self.date = parse(data["date"])
        total_amount = Decimal(data["amount"])
        self.fee = total_amount * PAYMENT_FEE_RATE
        self.amount = total_amount - self.fee

        if "bank_account_id" in data:
            id_key = "bank_account_id"
            bank = Bank()
            bank.bank_account_id = int(data[id_key])
            bank.status = 'success'
            self.bank = bank
        elif "card_id" in data:
            id_key = "card_id"
            card = Card()
            card.card_id = int(data.get(id_key))
            card.status = data["card_status"]
            self.card = card
Esempio n. 12
0
    def __init__(self, data=None, source="card"):

        if not data:
            return

        self.customer_id = int(data["customer_id"])
        self.date = parse(data["date"])

        total_amount = Decimal(data["amount"])
        self.fee = total_amount * PAYMENT_FEE_RATE
        self.amount = total_amount - self.fee

        if (source == "card"):
            card = Card()
            card.card_id = int(data["card_id"])
            card.status = data["card_status"]
            self.card = card
        elif (source == "bank"):
            bank = Bank()
            bank.bank_account_id = data["bank_account_id"]
            bank.status = "processed"
            self.bank = bank
Esempio n. 13
0
    def __init__(self, data=None):

        if not data:
            return

        self.customer_id = int(data["customer_id"])
        self.date = parse(data["date"])

        total_amount = Decimal(data["amount"])
        self.fee = total_amount * PAYMENT_FEE_RATE
        self.amount = total_amount - self.fee

        if data.get("source") == "bank":
            bank = Bank()
            bank.bank_account_id = int(data["bank_account_id"])
            bank.status = data["bank_status"]
            self.bank = bank
            self.source = "bank"
        else:
            self.source = "card"
            card = Card()
            card.card_id = int(data["card_id"])
            card.status = data["card_status"]
            self.card = card
Esempio n. 14
0
    def __init__(self, data=None):

        if not data:
            return

        self.customer_id = int(data["customer_id"])
        self.date = parse(data["date"])

        total_amount = Decimal(data["amount"])
        self.fee = total_amount * PAYMENT_FEE_RATE
        self.amount = total_amount - self.fee

        card_id = data.get("card_id" or None)
        bank_acc_id = data.get("bank_account_id" or None)

        if card_id is not None:
            card = Card()
            card.card_id = int(card_id)
            card.status = data["card_status"]
            self.card = card
        elif bank_acc_id is not None:
            bank = Bank()
            bank.bank_account_id = int(bank_acc_id)
            self.bank = bank
Esempio n. 15
0
    def __init__(self, data=None, source=None):

        if not data or not source or source not in ["card", "bank"]:
            return
        self.source = source
        self._card = None
        self._bank_account = None

        self.payment_type = None
        if source == "card":
            self.payment_type = Card(data)
            self._card = self.payment_type
        elif source == "bank":
            self.payment_type = BankAccount(data)
            self._bank_account = self.payment_type
        else:
            raise ValueError("Please provide source either (card or bank)")
        if self.payment_type:
            self.__dict__.update(self.payment_type.__dict__)
Esempio n. 16
0
 def setUp(self):
     self.payment_mode = CardPayment()
     self.card = Card()
Esempio n. 17
0
    def test_no_source_is_not_successful(self):
        card = Card()
        payment = Payment()
        payment.card = card

        self.assertFalse(payment.is_successful())