Fix payment name params in PayPal

This commit is contained in:
Nathan Chapman 2022-05-20 17:17:03 -06:00
parent 05506503bf
commit dd656a7dcf
3 changed files with 14 additions and 17 deletions

View File

@ -3,7 +3,9 @@ import sys
import json import json
import logging import logging
from paypalcheckoutsdk.core import PayPalHttpClient, SandboxEnvironment, LiveEnvironment from paypalcheckoutsdk.core import (
PayPalHttpClient, SandboxEnvironment, LiveEnvironment
)
from paypalcheckoutsdk.orders import OrdersCreateRequest, OrdersCaptureRequest from paypalcheckoutsdk.orders import OrdersCreateRequest, OrdersCaptureRequest
from paypalhttp.serializers.json_serializer import Json from paypalhttp.serializers.json_serializer import Json
@ -91,19 +93,14 @@ class CreateOrder(PayPalClient):
processed_items = [ processed_items = [
{ {
# Shows within upper-right dropdown during payment approval # Shows within upper-right dropdown during payment approval
"name": f'{item["product"]}: ' "name": f'{item["product"]}: ' + ', '.join([
", ".join( next((
[
next(
(
f"{value['quantity']} x {v[1]}" f"{value['quantity']} x {v[1]}"
for i, v in enumerate(CoffeeGrind.GRIND_CHOICES) for i, v in enumerate(CoffeeGrind.GRIND_CHOICES)
if v[0] == key if v[0] == key
), ),
None, None,
) ) for key, value in item["variations"].items()]
for key, value in item["variations"].items()
]
)[:100], )[:100],
# Item details will also be in the completed paypal.com # Item details will also be in the completed paypal.com
# transaction view # transaction view

View File

@ -21,8 +21,8 @@ class RequestFaker:
}, },
'items': [ 'items': [
{ {
'name': 'Decaf', 'name': 'Decaf: 1 x Whole Beans, 2 x Percolator',
'description': '1 x Whole Beans, 2 x Percolator', 'description': '',
'unit_amount': {'currency_code': 'USD', 'value': '13.40'}, 'unit_amount': {'currency_code': 'USD', 'value': '13.40'},
'quantity': '3', 'quantity': '3',
} }

View File

@ -20,6 +20,7 @@ from . import RequestFaker
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class CreateOrderTest(TestCase): class CreateOrderTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
@ -35,7 +36,6 @@ class CreateOrderTest(TestCase):
def setUp(self): def setUp(self):
self.client = Client() self.client = Client()
def test_build_request_body(self): def test_build_request_body(self):
product_list_url = reverse('storefront:product-list') product_list_url = reverse('storefront:product-list')
response = self.client.get(product_list_url, follow=True) response = self.client.get(product_list_url, follow=True)