def create_payment(delivery_group):
order = delivery_group.order
status = random.choice(
[PaymentStatus.WAITING, PaymentStatus.PREAUTH, PaymentStatus.CONFIRMED])
payment = Payment.objects.create(
order=order,
status=status,
variant='default',
transaction_id=str(fake.random_int(1, 100000)),
currency=settings.DEFAULT_CURRENCY,
total=order.get_total().gross,
delivery=delivery_group.shipping_price.gross,
customer_ip_address=fake.ipv4(),
billing_first_name=order.billing_address.first_name,
billing_last_name=order.billing_address.last_name,
billing_address_1=order.billing_address.street_address_1,
billing_city=order.billing_address.city,
billing_postcode=order.billing_address.postal_code,
billing_country_code=order.billing_address.country)
if status == PaymentStatus.CONFIRMED:
payment.captured_amount = payment.total
payment.save()
return payment
评论列表
文章目录