Skip to content

Commit 264c197

Browse files
Added payment data in graphapi
1 parent a8a3c9d commit 264c197

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

nxtbn/admin_schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from nxtbn.core.admin_mutation import CoreMutation
55
from nxtbn.core.admin_queries import AdminCoreQuery
66
from nxtbn.order.admin_mutation import AdminOrderMutation
7+
from nxtbn.payment.admin_queries import AdminPaymentQuery
78
from nxtbn.product.admin_mutations import ProductMutation
89
from nxtbn.product.admin_queries import ProductQuery
910
from nxtbn.users.admin_mutation import AdminUserMutation
@@ -14,7 +15,7 @@
1415

1516

1617

17-
class Query(ProductQuery, AdminOrderQuery, AdminCoreQuery, WarehouseQuery, AdminCartQuery, UserAdminQuery, PurchaseQuery):
18+
class Query(ProductQuery, AdminOrderQuery, AdminCoreQuery, WarehouseQuery, AdminCartQuery, UserAdminQuery, PurchaseQuery, AdminPaymentQuery):
1819
pass
1920

2021
class Mutation(AdminUserMutation, ProductMutation, CoreMutation, AdminOrderMutation):

nxtbn/payment/admin_queries.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from django.conf import settings
2+
import graphene
3+
from graphene_django.filter import DjangoFilterConnectionField
4+
5+
from nxtbn.core.admin_permissions import gql_store_admin_required
6+
from nxtbn.payment.admin_types import PaymentType
7+
from nxtbn.payment.models import Payment
8+
9+
10+
class AdminPaymentQuery(graphene.ObjectType):
11+
payments = DjangoFilterConnectionField(PaymentType)
12+
payment = graphene.Field(PaymentType, id=graphene.Int(required=True))
13+
14+
@gql_store_admin_required
15+
def resolve_payments(self, info, **kwargs):
16+
return Payment.objects.all()
17+
18+
@gql_store_admin_required
19+
def resolve_payment(self, info, id):
20+
try:
21+
payment = Payment.objects.get(id=id)
22+
except Payment.DoesNotExist:
23+
raise Exception("Payment not found")
24+
25+
return payment

nxtbn/payment/admin_types.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from django.conf import settings
2+
import graphene
3+
from graphene_django import DjangoObjectType
4+
from graphene import relay
5+
6+
from nxtbn.payment.models import Payment
7+
8+
class PaymentType(DjangoObjectType):
9+
db_id = graphene.Int(source='id')
10+
11+
class Meta:
12+
model = Payment
13+
fields = (
14+
'id',
15+
'user',
16+
'order',
17+
'payment_method',
18+
'transaction_id',
19+
'payment_status',
20+
'is_successful',
21+
'currency',
22+
'payment_amount',
23+
'gateway_response_raw',
24+
'paid_at',
25+
'payment_plugin_id',
26+
'gateway_name',
27+
)
28+
29+
interfaces = (relay.Node,)
30+
filter_fields = (
31+
'order__alias',
32+
)

0 commit comments

Comments
 (0)