|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
from django.db import models
|
|
|
|
|
from osinacore.models import *
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create your models here.
|
|
|
|
|
|
|
|
|
@ -51,6 +53,26 @@ class OrderItem(models.Model):
|
|
|
|
|
purchased_at = models.DateField(null=True, blank=True)
|
|
|
|
|
due_at = models.DateField(blank=True, null=True)
|
|
|
|
|
recurring_cycle = models.ForeignKey(RecurringCycle, on_delete=models.SET_NULL, null=True, blank=True)
|
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
|
if self.purchased_at:
|
|
|
|
|
try:
|
|
|
|
|
customer_email = self.order.customer.email
|
|
|
|
|
plan_name = self.item.title
|
|
|
|
|
|
|
|
|
|
payload = {
|
|
|
|
|
'email': customer_email,
|
|
|
|
|
'plan': plan_name
|
|
|
|
|
}
|
|
|
|
|
response = requests.post('https://osimenu.com/api/create-subscription/', data=payload)
|
|
|
|
|
|
|
|
|
|
if response.status_code == 201:
|
|
|
|
|
print('Subscription created successfully')
|
|
|
|
|
else:
|
|
|
|
|
print('Failed to create subscription')
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f'Error creating subscription: {e}')
|
|
|
|
|
|
|
|
|
|
super(OrderItem, self).save(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|