def test_payment_method_restrictions(self): # Test country restrictions. payment_method_ids = factory.get_payment_method_ids(country='NL') self.assertTrue('dd-ideal' in payment_method_ids, "dd-ideal not is in payment method list.") self.assertTrue(len(payment_method_ids) > 1, "Payment method list should have two or more payment methods.") payment_method_ids = factory.get_payment_method_ids(country='CA') self.assertTrue('dd-ideal' not in payment_method_ids, "dd-ideal should not be in payment method list.") # Test recurring restrictions. payment_method_ids = factory.get_payment_method_ids(recurring=True) self.assertTrue(len(payment_method_ids) == 1, "Payment method list should have one entry.")
def get_object(self, queryset=None): order = self.get_current_order() if not order: raise exceptions.ParseError(detail=no_active_order_error_msg) # Use the order for the permissions of the payment. If a user can access the order, they can access the payment. self.check_object_permissions(self.request, order) payment = order.payment # We're relying on the fact that the Payment is created when the Order is created. This assert # verifies this assumption in case the Order creation code changes in the future. assert payment # Clear the payment method if it's not in the list of available methods. # Using 'payment.country' like this assumes that payment is a DocDataPaymentOrder. assert isinstance(payment, DocDataPaymentOrder) available_payment_methods = factory.get_payment_method_ids(amount=payment.amount, currency=payment.currency, country=payment.country, recurring=order.recurring) if payment.payment_method_id and not payment.payment_method_id in available_payment_methods: payment.payment_method_id = '' payment.save() return payment
def get_available_payment_methods(self, payment): order = payment.orders.all()[0] # Using 'payment.country' like this assumes that payment is a DocDataPaymentOrder. assert isinstance(payment, DocDataPaymentOrder) return factory.get_payment_method_ids(amount=payment.amount, currency=payment.currency, country=payment.country, recurring=order.recurring)