Fakultas Ilmu Komputer UI

Commit 00220d46 authored by Glenda Emanuella Sutanto's avatar Glenda Emanuella Sutanto
Browse files

Merge branch 'PBI-8-AddTransactionStatus' into 'staging'

Midtrans Redirection URL

See merge request !52
parents 9ce7205b 49cf21b5
Pipeline #73608 passed with stages
in 9 minutes and 6 seconds
...@@ -21,6 +21,7 @@ class CartTests(APITestCase): ...@@ -21,6 +21,7 @@ class CartTests(APITestCase):
def setUpTestData(cls): def setUpTestData(cls):
cls.BASE_URL = "/payment/cart/" cls.BASE_URL = "/payment/cart/"
cls.SET_TRANSACTION_STATUS_URL = "/payment/set-transaction-status/" cls.SET_TRANSACTION_STATUS_URL = "/payment/set-transaction-status/"
cls.MIDTRANS_REDIRECTION_URL = "/payment/midtrans-redirection/"
cls.dietela_program_1 = DietelaProgram.objects.create( cls.dietela_program_1 = DietelaProgram.objects.create(
unique_code="PRG1", unique_code="PRG1",
...@@ -136,6 +137,17 @@ class CartTests(APITestCase): ...@@ -136,6 +137,17 @@ class CartTests(APITestCase):
response = self.client.post(url, data, format='json') response = self.client.post(url, data, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_midtrans_redirection(self):
url = self.MIDTRANS_REDIRECTION_URL
request_params = {
'order_id': self.cart_3.id,
'status_code': 201,
'transaction_status': 'pending'
}
response = self.client.get(url, request_params)
self.assertEqual(response.status_code, status.HTTP_200_OK)
@patch('payment.views.json.loads') @patch('payment.views.json.loads')
class TestPaymentIntegration(TestCase): class TestPaymentIntegration(TestCase):
......
from rest_framework import routers from rest_framework import routers
from .views import CartViewSet, PaymentViewSet, TransactionStatusViewSet from .views import CartViewSet, PaymentViewSet, TransactionStatusViewSet, \
MidtransRedirectionViewSet
router = routers.SimpleRouter() router = routers.SimpleRouter()
router.register('payment/cart', CartViewSet) router.register('payment/cart', CartViewSet)
...@@ -7,6 +8,8 @@ router.register('payment/midtrans', PaymentViewSet, \ ...@@ -7,6 +8,8 @@ router.register('payment/midtrans', PaymentViewSet, \
basename="Payment") basename="Payment")
router.register('payment/set-transaction-status', TransactionStatusViewSet, \ router.register('payment/set-transaction-status', TransactionStatusViewSet, \
basename="TransactionStatus") basename="TransactionStatus")
router.register('payment/midtrans-redirection', MidtransRedirectionViewSet, \
basename="MidtransRedirection")
urlpatterns = [] urlpatterns = []
......
...@@ -92,3 +92,17 @@ class TransactionStatusViewSet(viewsets.ViewSet): ...@@ -92,3 +92,17 @@ class TransactionStatusViewSet(viewsets.ViewSet):
cart.save() cart.save()
return Response(status=status.HTTP_200_OK) return Response(status=status.HTTP_200_OK)
class MidtransRedirectionViewSet(viewsets.ViewSet):
@staticmethod
def list(request):
transaction_status = request.query_params['transaction_status']
cart_id = request.query_params['order_id']
cart = Cart.objects.get(pk=cart_id)
cart.transaction_status = transaction_status
cart.save()
return Response(status=status.HTTP_200_OK)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment