Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
fix: Modify FulfillFrozenBaskets to account for Stripe DPM payments
Browse files Browse the repository at this point in the history
  • Loading branch information
julianajlk committed Apr 9, 2024
1 parent 71ac11b commit b877cb0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
32 changes: 29 additions & 3 deletions ecommerce/management/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from ecommerce.extensions.payment.models import PaymentProcessorResponse
from ecommerce.extensions.payment.processors.cybersource import Cybersource
from ecommerce.extensions.payment.processors.paypal import Paypal
from ecommerce.extensions.payment.processors.stripe import Stripe
from ecommerce.extensions.test.factories import create_basket, prepare_voucher
from ecommerce.management.utils import FulfillFrozenBaskets, refund_basket_transactions
from ecommerce.tests.factories import UserFactory
Expand Down Expand Up @@ -60,13 +61,23 @@ def test_failure(self):
class FulfillFrozenBasketsTests(TestCase):
""" Test Fulfill Frozen Basket class"""

def _dummy_basket_data(self):
def _dummy_basket_data(self, payment_procesor=None):
""" Creates dummy basket data for testing."""
basket = create_basket(site=self.site)
basket.status = 'Frozen'
basket.save()
PaymentProcessorResponse.objects.create(basket=basket, transaction_id='PAY-123', processor_name='paypal',
response={'state': 'approved'})
response = {
'state': 'approved',
'payment_method': {
'type': 'affirm'
}
}
if payment_procesor:
PaymentProcessorResponse.objects.create(
basket=basket, transaction_id='pi_123dummy', processor_name=payment_procesor, response=response)
else:
PaymentProcessorResponse.objects.create(
basket=basket, transaction_id='PAY-123', processor_name='paypal', response={'state': 'approved'})
return basket

@staticmethod
Expand Down Expand Up @@ -125,6 +136,21 @@ def test_success_with_paypal(self):
PaymentEvent.objects.get(event_type__name=PaymentEventTypeName.PAID, amount=total,
processor_name=Paypal.NAME)

def test_success_with_stripe_dynamic_payment_methods(self):
""" Test basket with Stripe DPM payment basket."""
basket = self._dummy_basket_data(payment_procesor='stripe')
assert FulfillFrozenBaskets().fulfill_basket(basket.id, self.site)

order = Order.objects.get(number=basket.order_number)
assert order.status == 'Complete'

total = basket.total_incl_tax_excl_discounts
Source.objects.get(
source_type__name=Stripe.NAME, currency=order.currency, amount_allocated=total, amount_debited=total,
label='Stripe affirm', card_type=None)
PaymentEvent.objects.get(event_type__name=PaymentEventTypeName.PAID, amount=total,
processor_name=Stripe.NAME)

def test_multiple_transactions(self):
""" Test utility against multiple payment processor responses."""
basket = self._dummy_basket_data()
Expand Down
11 changes: 8 additions & 3 deletions ecommerce/management/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,14 @@ def get_card_info_from_payment_notification(payment_notification):
card_number = 'Paypal Account'
card_type = None
elif payment_notification.transaction_id.startswith('pi_'):
card_number = payment_notification.response['payment_method']['card']['last4']
stripe_card_type = payment_notification.response['payment_method']['card']['brand']
card_type = STRIPE_CARD_TYPE_MAP[stripe_card_type]
payment_type = payment_notification.response['payment_method']['type']
if payment_type == 'card':
card_number = payment_notification.response['payment_method']['card']['last4']
stripe_card_type = payment_notification.response['payment_method']['card']['brand']
card_type = STRIPE_CARD_TYPE_MAP[stripe_card_type]
else:
card_number = 'Stripe {}'.format(payment_type)
card_type = None
else:
card_number = payment_notification.response['req_card_number']
cybersource_card_type = payment_notification.response['req_card_type']
Expand Down

0 comments on commit b877cb0

Please sign in to comment.