def test_payment_methods_pool():
    assert len(payment_methods_pool.get_payments()) == 3
    assert len(payment_methods_pool.get_payments('order')) == 2
    assert len(payment_methods_pool.get_payments('basket')) == 1
    assert len(payment_methods_pool.get_urls()) == 3
    assert len(payment_methods_pool.get_choices()) == 3
    assert len(payment_methods_pool.get_choices('order')) == 2
    assert len(payment_methods_pool.get_choices('basket')) == 1
    assert payment_methods_pool.get_payment('dummy2').label == 'Dummy 2'
    assert not payment_methods_pool.get_payment('non-existant')
Exemple #2
0
    def get_payment_method(self):
        """
        Returns payment method instance.
        """
        from salesman.checkout.payment import payment_methods_pool

        return payment_methods_pool.get_payment(self.payment_method)
Exemple #3
0
 def save(self):
     # Process the refund.
     order = self.context['order']
     refunded, failed = [], []
     for item in order.payments.all():
         payment = payment_methods_pool.get_payment(item.payment_method)
         serializer = OrderPaymentSerializer(item)
         if payment and payment.refund_payment(item):
             refunded.append(serializer.data)
         else:
             failed.append(serializer.data)
     # Set data and change order status.
     self.validated_data.update({'refunded': refunded, 'failed': failed})
     if not failed:
         order.status = order.statuses.REFUNDED
         order.save(update_fields=['status'])
Exemple #4
0
 def validate_payment_method(self, value):
     order, request = self.context['order'], self.context['request']
     payment = payment_methods_pool.get_payment(value)
     payment.validate_order(order, request)
     return payment