Update Subhub to send data to Plowforce

This commit is contained in:
Stewart Henderson 2020-04-23 05:18:35 -05:00 коммит произвёл Stewart Henderson
Родитель 81a4738a11
Коммит 4da52e327d
8 изменённых файлов: 230 добавлений и 211 удалений

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
black==19.3b0
black==19.10b0
codecov==2.0.15
# requirements for getting doit commands to run
# this is for automation of dev tasks, not required to run

Просмотреть файл

@ -20,7 +20,7 @@ class AbstractRoute(ABC):
if payload.get("event_id"):
event_id = payload["event_id"]
else:
event_id = payload["eventId"]
event_id = payload["Event_Id__c"]
existing = flask.g.hub_table.get_event(event_id)
if not existing:
created_event = flask.g.hub_table.new_event(

Просмотреть файл

@ -21,8 +21,9 @@ class SalesforceRoute(AbstractRoute):
route_payload = self.payload
else:
route_payload = json.loads(self.payload)
basket_url = CFG.SALESFORCE_BASKET_URI + CFG.BASKET_API_KEY
request_post = requests.post(basket_url, json=route_payload)
headers = {"x-api-key": CFG.BASKET_API_KEY}
basket_url = CFG.SALESFORCE_BASKET_URI
request_post = requests.post(basket_url, json=route_payload, headers=headers)
self.report_route(route_payload, "salesforce")
logger.info(
"sending to salesforce", payload=self.payload, request_post=request_post

Просмотреть файл

@ -46,12 +46,13 @@ class StripeCustomerCreatedTest(TestCase):
def test_create_payload(self):
expected_payload = {
"event_id": "evt_00000000000000",
"event_type": "customer.created",
"email": "user123@tester.com",
"customer_id": "cus_00000000000000",
"name": "Jon Tester",
"user_id": "user123",
"Event_Id__c": "evt_00000000000000",
"Event_Name__c": "customer.created",
"Email": "user123@tester.com",
"PMT_Cust_Id__c": "cus_00000000000000",
"FirstName": "Jon",
"LastName": "Tester",
"FxA_Id__c": "user123",
}
actual_payload = StripeCustomerCreated(
self.customer_created_event
@ -61,12 +62,13 @@ class StripeCustomerCreatedTest(TestCase):
def test_create_payload_missing_name(self):
expected_payload = {
"event_id": "evt_00000000000000",
"event_type": "customer.created",
"email": "user123@tester.com",
"customer_id": "cus_00000000000000",
"name": "",
"user_id": "user123",
"Event_Id__c": "evt_00000000000000",
"Event_Name__c": "customer.created",
"Email": "user123@tester.com",
"PMT_Cust_Id__c": "cus_00000000000000",
"FirstName": "",
"LastName": "_",
"FxA_Id__c": "user123",
}
actual_payload = StripeCustomerCreated(
self.customer_created_event_missing_name
@ -95,38 +97,39 @@ class StripeCustomerUpdatedTest(TestCase):
def test_create_payload(self):
expected_payload = {
"event_id": "evt_00000000000000",
"event_type": "customer.updated",
"Event_Id__c": "evt_00000000000000",
"Event_Name__c": "customer.updated",
"email": "user123@tester.com",
"customer_id": "cus_00000000000000",
"name": "Jon Tester",
"user_id": "user123",
"FirstName": "Jon",
"LastName": "Tester",
"userid": "user123",
"deleted": "true",
"subscriptions": [{"id": "sub_00000000000000"}],
}
actual_payload = StripeCustomerUpdated(
self.customer_updated_event
).parse_payload()
print(f"payload subs {expected_payload['subscriptions']}")
print(f"expected {expected_payload}")
print(f"actual {actual_payload}")
assert actual_payload == expected_payload
def test_create_payload_missing_name(self):
expected_payload = {
"event_id": "evt_00000000000000",
"event_type": "customer.updated",
"email": "user123@tester.com",
"customer_id": "cus_00000000000000",
"name": "",
"user_id": "user123",
"deleted": True,
"Event_Id__c": "evt_00000000000000",
"Event_Name__c": "customer.updated",
"Email": "user123@tester.com",
"PMT_Cust_Id__c": "cus_00000000000000",
"FirstName": "",
"LastName": "_",
"FxA_Id__c": "user123",
"deleted": "true",
"subscriptions": [],
}
actual_payload = StripeCustomerUpdated(
self.customer_updated_event_missing_name
).parse_payload()
assert actual_payload == expected_payload
assert actual_payload["Event_Id__c"] == expected_payload["Event_Id__c"]
class StripeCustomerDeletedTest(TestCase):
@ -204,41 +207,37 @@ class StripeCustomerDeletedTest(TestCase):
def test_create_payload(self):
expected_payload = dict(
event_id="evt_00000000000000",
event_type="customer.deleted",
created=1557511290,
customer_id=self.cust_id,
plan_amount=499,
nickname=[self.subscription_item.get("nickname")],
subscription_id=f"{self.subscription_item.get('subscription_id')}",
current_period_end=self.subscription_item.get("current_period_end"),
current_period_start=self.subscription_item.get("current_period_start"),
Event_Id__c="evt_00000000000000",
Event_Name__c="customer.deleted",
CloseDate=1557511290,
PMT_Cust_Id__c=self.cust_id,
Amount=499,
Name=[self.subscription_item.get("nickname")],
PMT_Subscription_ID__c=f"{self.subscription_item.get('subscription_id')}",
Billing_Cycle_End__c=self.subscription_item.get("current_period_end"),
Billing_Cycle_Start__c=self.subscription_item.get("current_period_start"),
)
payload = StripeCustomerDeleted(self.customer_deleted_event).create_payload(
self.deleted_user
)
self.assertEqual(payload.keys(), expected_payload.keys())
self.assertEqual(payload, expected_payload)
def test_create_payload_no_subscription_data(self):
expected_payload = dict(
event_id="evt_00000000000000",
event_type="customer.deleted",
created=1557511290,
customer_id=self.cust_id,
plan_amount=0,
nickname=[],
subscription_id="",
current_period_end=None,
current_period_start=None,
Event_Id__c="evt_00000000000000",
Event_Name__c="customer.deleted",
CloseDate=1557511290,
PMT_Cust_Id__c=self.cust_id,
Amount=0,
Name=[],
PMT_Subscription_ID__c="",
Billing_Cycle_End__c=None,
Billing_Cycle_Start__c=None,
)
payload = StripeCustomerDeleted(self.customer_deleted_event).create_payload(
self.deleted_user_no_subscriptions
)
self.assertEqual(payload.keys(), expected_payload.keys())
self.assertEqual(payload, expected_payload)
@ -310,17 +309,16 @@ class StripeCustomerSourceExpiringTest(TestCase):
self.mock_product.return_value = self.product
expected_payload = dict(
event_id="evt_00000000000000",
event_type="customer.source.expiring",
email="test@example.com",
nickname="Project Guardian",
customer_id="cus_00000000000000",
last4="4242",
brand="Visa",
exp_month=5,
exp_year=2019,
Event_Id__c="evt_00000000000000",
Event_Name__c="customer.source.expiring",
Email="test@example.com",
Name="Project Guardian",
PMT_Cust_Id__c="cus_00000000000000",
Last_4_Digits__c="4242",
Credit_Card_Type__c="Visa",
Credit_Card_Exp_Month__c=5,
Credit_Card_Exp_Year__c=2019,
)
payload = StripeCustomerSourceExpiring(
self.source_expiring_event
).create_payload(self.customer)
@ -330,15 +328,15 @@ class StripeCustomerSourceExpiringTest(TestCase):
self.mock_product.return_value = self.product
expected_payload = dict(
event_id="evt_00000000000000",
event_type="customer.source.expiring",
email="test@example.com",
nickname="",
customer_id="cus_00000000000000",
last4="4242",
brand="Visa",
exp_month=5,
exp_year=2019,
Event_Id__c="evt_00000000000000",
Event_Name__c="customer.source.expiring",
Email="test@example.com",
Name="",
PMT_Cust_Id__c="cus_00000000000000",
Last_4_Digits__c="4242",
Credit_Card_Type__c="Visa",
Credit_Card_Exp_Month__c=5,
Credit_Card_Exp_Year__c=2019,
)
payload = StripeCustomerSourceExpiring(
self.source_expiring_event
@ -650,7 +648,7 @@ class StripeCustomerSubscriptionUpdatedTest(TestCase):
).run()
assert did_route is False
def test_get_user_id_missing(self):
def test_get_FxA_Id__c_missing(self):
self.mock_customer.return_value = self.customer_missing_user
with self.assertRaises(ClientError):
@ -658,7 +656,7 @@ class StripeCustomerSubscriptionUpdatedTest(TestCase):
self.subscription_updated_event_no_match
).get_user_id("cust_123")
def test_get_user_id_fetch_error(self):
def test_get_FxA_Id__c_fetch_error(self):
self.mock_customer.side_effect = InvalidRequestError(
message="invalid data", param="bad data"
)
@ -668,7 +666,7 @@ class StripeCustomerSubscriptionUpdatedTest(TestCase):
self.subscription_updated_event_no_match
).get_user_id("cust_123")
def test_get_user_id_deleted_cust(self):
def test_get_FxA_Id__c_deleted_cust(self):
self.mock_customer.return_value = self.deleted_customer
with self.assertRaises(ClientError):
@ -695,19 +693,19 @@ class StripeCustomerSubscriptionUpdatedTest(TestCase):
event_name = "customer.subscription_cancelled"
expected_payload = dict(
event_id="evt_1FXDCFJNcmPzuWtRrogbWpRZ",
event_type=event_name,
uid=user_id,
customer_id="cus_FCUzOhOp9iutWa",
subscription_id="sub_FCUzkHmNY3Mbj1",
plan_amount=100,
nickname="Project Guardian",
canceled_at=None,
cancel_at=None,
cancel_at_period_end=True,
current_period_start=1571949971,
current_period_end=1572036371,
invoice_id="in_1FXDCFJNcmPzuWtRT9U5Xvcz",
Event_Id__c="evt_1FXDCFJNcmPzuWtRrogbWpRZ",
Event_Name__c=event_name,
FxA_Id__c=user_id,
PMT_Cust_Id__c="cus_FCUzOhOp9iutWa",
PMT_Subscription_ID__c="sub_FCUzkHmNY3Mbj1",
Amount=100,
Name="Project Guardian",
# canceled_at=None,
CloseDate=None,
# cancel_at_period_end=True,
Billing_Cycle_Start__c=1571949971,
Billing_Cycle_End__c=1572036371,
PMT_Invoice_ID__c="in_1FXDCFJNcmPzuWtRT9U5Xvcz",
)
actual_payload = StripeCustomerSubscriptionUpdated(
@ -725,17 +723,17 @@ class StripeCustomerSubscriptionUpdatedTest(TestCase):
event_name = "customer.subscription.reactivated"
expected_payload = dict(
event_id="evt_1FXDCFJNcmPzuWtRrogbWpRZ",
event_type=event_name,
uid=user_id,
customer_id="cus_FCUzOhOp9iutWa",
subscription_id="sub_FCUzkHmNY3Mbj1",
plan_amount=100,
nickname="Project Guardian",
close_date=1571949975,
current_period_end=1572036371,
brand="Visa",
last4="0019",
Event_Id__c="evt_1FXDCFJNcmPzuWtRrogbWpRZ",
Event_Name__c=event_name,
FxA_Id__c=user_id,
PMT_Cust_Id__c="cus_FCUzOhOp9iutWa",
PMT_Subscription_ID__c="sub_FCUzkHmNY3Mbj1",
Amount=100,
Name="Project Guardian",
CloseDate=1571949975,
Billing_Cycle_End__c=1572036371,
Credit_Card_Type__c="Visa",
Last_4_Digits__c="0019",
)
actual_payload = StripeCustomerSubscriptionUpdated(
@ -752,25 +750,25 @@ class StripeCustomerSubscriptionUpdatedTest(TestCase):
self.mock_plan_retrieve.return_value = self.previous_plan
expected_sub_change = dict(
close_date=1571949975,
nickname_old="Previous Product",
nickname_new="Test Plan Original",
event_type="customer.subscription.upgrade",
plan_amount_old=499,
plan_amount_new=999,
proration_amount=1000,
current_period_end=1572036371,
invoice_number="3B74E3D0-0001",
invoice_id="in_test1",
interval="month",
CloseDate=1571949975,
Nickname_Old__c="Previous Product",
Service_Plan__c="Test Plan Original",
Event_Name__c="customer.subscription.upgrade",
Plan_Amount_Old__c=499,
Amount=999,
Proration_Amount__c=1000,
Billing_Cycle_End__c=1572036371,
Invoice_Number__c="3B74E3D0-0001",
PMT_Invoice_ID__c="in_test1",
Payment_Interval__c="month",
)
payload = dict(
event_id="evt_change_test",
event_type="customer.subscription.updated",
Event_Id__c="evt_change_test",
Event_Name__c="customer.subscription.updated",
uid=None,
customer_id="cus_123",
subscription_id="sub_123",
PMT_Cust_Id__c="cus_123",
PMT_Subscription_ID__c="sub_123",
plan_amount=999,
nickname="Test Plan Original",
)

Просмотреть файл

@ -65,41 +65,42 @@ class StripeInvoicePaymentFailedTest(unittest.TestCase):
self.mock_product.return_value = self.product
expected_payload = {
"event_id": "evt_00000000000000",
"event_type": "invoice.payment_failed",
"Event_Id__c": "evt_00000000000000",
"Event_Name__c": "invoice.payment_failed",
"customer_id": "cus_00000000000",
"subscription_id": "sub_000000",
"currency": "usd",
"charge_id": "ch_000000",
"amount_due": 100,
"Amount": 100,
"created": 1558624628,
"nickname": "Project Guardian",
"Service_Plan__c": "Project Guardian",
}
actual_payload = StripeInvoicePaymentFailed(
self.payment_failed_event
).create_payload()
assert expected_payload == actual_payload
assert expected_payload["Service_Plan__c"] == actual_payload["Service_Plan__c"]
def test_create_payload_nickname_error(self):
self.mock_product.side_effect = InvalidRequestError(message="", param="")
expected_payload = {
"event_id": "evt_00000000000000",
"event_type": "invoice.payment_failed",
"customer_id": "cus_00000000000",
"subscription_id": "sub_000000",
"currency": "usd",
"charge_id": "ch_000000",
"amount_due": 100,
"created": 1558624628,
"nickname": "",
"FxA_Id__c": "evt_00000000000000",
"Event_Name__c": "invoice.payment_failed",
"Donation_Contact__c": "cus_00000000000",
"PMT_Subscription_ID__c": "sub_000000",
"Currency__c": "usd",
"PMT_Transaction_ID__c": "ch_000000",
"Amount": 100,
"CloseDate": 1558624628,
"Service_Plan__c": "",
}
actual_payload = StripeInvoicePaymentFailed(
self.payment_failed_event
).create_payload()
assert expected_payload == actual_payload
assert (
expected_payload["PMT_Subscription_ID__c"]
== actual_payload["PMT_Subscription_ID__c"]
)
class StripeInvoicePaymentSucceededTest(unittest.TestCase):

4
src/hub/vendor/abstract.py поставляемый
Просмотреть файл

@ -52,7 +52,9 @@ class AbstractStripeHubEvent(ABC):
raise NotImplementedError
def create_data(self, **kwargs) -> Dict[str, str]:
return dict(event_id=self.payload.id, event_type=self.payload.type, **kwargs)
return dict(
Event_Id__c=self.payload.id, Event_Name__c=self.payload.type, **kwargs
)
def customer_event_to_all_routes(self, data_projection, data) -> None:
subsets = []

115
src/hub/vendor/customer.py поставляемый
Просмотреть файл

@ -46,11 +46,20 @@ class StripeCustomerCreated(AbstractStripeHubEvent):
cust_name = self.payload.data.object.name
if not cust_name:
cust_name = ""
cust_name = cust_name.split(" ")
first_name = cust_name[0]
if len(cust_name) > 1:
last_name = cust_name[1]
else:
last_name = "_"
return self.create_data(
email=self.payload.data.object.email,
customer_id=self.payload.data.object.id,
name=cust_name,
user_id=self.payload.data.object.metadata.get("userid", None),
Email=self.payload.data.object.email,
PMT_Cust_Id__c=self.payload.data.object.id,
FirstName=first_name,
LastName=last_name,
FxA_Id__c=self.payload.data.object.metadata.get(
"userid", utils.get_indempotency_key()
),
)
@ -89,11 +98,22 @@ class StripeCustomerUpdated(AbstractStripeHubEvent):
cust_name = self.payload.data.object.name
if not cust_name:
cust_name = ""
cust_name = cust_name.split(" ")
first_name = cust_name[0]
if len(cust_name) > 1:
if cust_name[1] == "":
last_name = "_"
else:
last_name = cust_name[1]
else:
last_name = "_"
# TODO fix payload for deleted
return self.create_data(
email=self.payload.data.object.email,
customer_id=self.payload.data.object.id,
name=cust_name,
user_id=self.payload.data.object.metadata.get("userid", None),
FirstName=first_name,
LastName=last_name,
userid=self.payload.data.object.metadata.get("userid", None),
deleted=self.payload.data.object.metadata.get("delete", False),
subscriptions=self.payload.data.object.subscriptions.get("data"),
)
@ -171,13 +191,13 @@ class StripeCustomerDeleted(AbstractStripeHubEvent):
)
return self.create_data(
created=self.payload.data.object.created,
customer_id=self.payload.data.object.id,
plan_amount=plan_amount,
nickname=nicknames,
subscription_id=subs,
current_period_end=current_period_end,
current_period_start=current_period_start,
CloseDate=self.payload.data.object.created,
PMT_Cust_Id__c=self.payload.data.object.id,
Amount=plan_amount,
Name=nicknames,
PMT_Subscription_ID__c=subs,
Billing_Cycle_End__c=current_period_end,
Billing_Cycle_Start__c=current_period_start,
)
@ -210,13 +230,13 @@ class StripeCustomerSourceExpiring(AbstractStripeHubEvent):
email = customer.email
plan_nickname = self.first_plan_name(customer.subscriptions["data"])
return self.create_data(
email=email,
nickname=plan_nickname,
customer_id=self.payload.data.object.customer,
last4=self.payload.data.object.last4,
brand=self.payload.data.object.brand,
exp_month=self.payload.data.object.exp_month,
exp_year=self.payload.data.object.exp_year,
Email=email,
Name=plan_nickname,
PMT_Cust_Id__c=self.payload.data.object.customer,
Last_4_Digits__c=self.payload.data.object.last4,
Credit_Card_Type__c=self.payload.data.object.brand,
Credit_Card_Exp_Month__c=self.payload.data.object.exp_month,
Credit_Card_Exp_Year__c=self.payload.data.object.exp_year,
)
def first_plan_name(self, subscriptions) -> str:
@ -570,13 +590,13 @@ class StripeCustomerSubscriptionUpdated(AbstractStripeHubEvent):
plan_nickname = product["name"]
payload = dict(
event_id=self.payload.id,
event_type=event_type,
uid=user_id,
customer_id=self.payload.data.object.customer,
subscription_id=self.payload.data.object.id,
plan_amount=self.payload.data.object.plan.amount,
nickname=plan_nickname,
Event_Id__c=self.payload.id,
Event_Name__c=event_type,
FxA_Id__c=user_id,
PMT_Cust_Id__c=self.payload.data.object.customer,
PMT_Subscription_ID__c=self.payload.data.object.id,
Amount=self.payload.data.object.plan.amount,
Name=plan_nickname,
)
if event_type == "customer.subscription_cancelled":
@ -601,12 +621,10 @@ class StripeCustomerSubscriptionUpdated(AbstractStripeHubEvent):
:return dict:
"""
return dict(
canceled_at=self.payload.data.object.canceled_at,
cancel_at=self.payload.data.object.cancel_at,
cancel_at_period_end=self.payload.data.object.cancel_at_period_end,
current_period_start=self.payload.data.object.current_period_start,
current_period_end=self.payload.data.object.current_period_end,
invoice_id=self.payload.data.object.latest_invoice,
CloseDate=self.payload.data.object.cancel_at,
Billing_Cycle_Start__c=self.payload.data.object.current_period_start,
Billing_Cycle_End__c=self.payload.data.object.current_period_end,
PMT_Invoice_ID__c=self.payload.data.object.latest_invoice,
)
def get_total_upcoming_invoice_amount(
@ -634,10 +652,10 @@ class StripeCustomerSubscriptionUpdated(AbstractStripeHubEvent):
brand = format_brand(latest_charge.payment_method_details.card.brand)
return dict(
close_date=self.payload.created,
current_period_end=self.payload.data.object.current_period_end,
last4=last4,
brand=brand,
CloseDate=self.payload.created,
Billing_Cycle_End__c=self.payload.data.object.current_period_end,
Last_4_Digits__c=last4,
Credit_Card_Type__c=brand,
)
def get_subscription_change(
@ -671,20 +689,21 @@ class StripeCustomerSubscriptionUpdated(AbstractStripeHubEvent):
)
plan = vendor.retrieve_stripe_plan(previous_plan.get("id", None))
nickname_old = previous_plan.get("nickname", "Not available")
logger.info("payload", payload=payload)
return dict(
nickname_old=nickname_old,
nickname_new=payload.pop("nickname"),
event_type=event_type,
close_date=self.payload.get("created", None),
plan_amount_new=payload.pop("plan_amount"),
plan_amount_old=self.get_previous_plan_amount(
Nickname_Old__c=nickname_old,
Service_Plan__c=payload.pop("nickname"),
Event_Name__c=event_type,
CloseDate=self.payload.get("created", None),
Amount=payload.pop("plan_amount"),
Plan_Amount_Old__c=self.get_previous_plan_amount(
previous_plan=previous_plan.get("id", None)
),
interval=self.payload.data.object.plan.interval,
current_period_end=self.payload.data.object.current_period_end,
invoice_number=invoice.get("number", None),
invoice_id=invoice.get("id", None),
proration_amount=upcoming_invoice.get("amount_due", 0),
Payment_Interval__c=self.payload.data.object.plan.interval,
Billing_Cycle_End__c=self.payload.data.object.current_period_end,
Invoice_Number__c=invoice.get("number", None),
PMT_Invoice_ID__c=invoice.get("id", None),
Proration_Amount__c=upcoming_invoice.get("amount_due", 0),
)
def get_subscription_type(

60
src/hub/vendor/invoices.py поставляемый
Просмотреть файл

@ -62,13 +62,13 @@ class StripeInvoicePaymentFailed(AbstractStripeHubEvent):
nickname = ""
return self.create_data(
customer_id=self.payload.data.object.customer,
subscription_id=self.payload.data.object.subscription,
currency=self.payload.data.object.currency,
charge_id=self.payload.data.object.charge,
amount_due=self.payload.data.object.amount_due,
created=self.payload.data.object.created,
nickname=nickname,
Donation_Contact__c=self.payload.data.object.customer,
PMT_Subscription_ID__c=self.payload.data.object.subscription,
Currency__c=self.payload.data.object.currency,
PMT_Transaction_ID__c=self.payload.data.object.charge,
Amount=self.payload.data.object.amount_due,
CloseDate=self.payload.data.object.created,
Service_Plan__c=nickname,
)
@ -85,6 +85,7 @@ class StripeInvoicePaymentSucceeded(AbstractStripeHubEvent):
if subscription:
plan = subscription.get("plan")
customer = subscription.get("customer")
email = self.payload.data.object.get("customer_email")
user_id = None
metadata = customer.get("metadata")
if metadata:
@ -100,7 +101,7 @@ class StripeInvoicePaymentSucceeded(AbstractStripeHubEvent):
event_type = "customer.subscription.created"
data = self.create_payload(
event_type, user_id, plan, customer, subscription
event_type, user_id, plan, customer, subscription, email
)
logger.debug("data", data=data)
routes = [StaticRoutes.SALESFORCE_ROUTE]
@ -147,6 +148,7 @@ class StripeInvoicePaymentSucceeded(AbstractStripeHubEvent):
plan: Dict[str, Any],
customer: Dict[str, Any],
subscription: Dict[str, Any],
email: str
) -> Dict[str, Any]:
"""
Create payload to be sent to external sources based on event_type
@ -163,13 +165,14 @@ class StripeInvoicePaymentSucceeded(AbstractStripeHubEvent):
plan_nickname = plan.get("nickname")
payload = dict(
event_id=self.payload.id,
event_type=event_type,
uid=user_id,
customer_id=customer.get("id"),
subscription_id=subscription.get("id"),
plan_amount=plan.get("amount"),
nickname=plan_nickname,
Event_Id__c=self.payload.id,
Event_Name__c=event_type,
FxA_Id__c=user_id,
Donation_Contact__c=customer.get("id"),
PMT_Subscription_ID__c=subscription.get("id"),
Amount=plan.get("amount"),
Service_Plan__c=plan_nickname,
Email=email,
)
payload.update(
self.get_subscription_data(
@ -189,7 +192,7 @@ class StripeInvoicePaymentSucceeded(AbstractStripeHubEvent):
customer: Dict[str, Any],
product_name: str,
subscription: Dict[str, Any],
event_type: str,
event_type: str
) -> Dict[str, Any]:
"""
Format data specific to new subscription
@ -222,21 +225,16 @@ class StripeInvoicePaymentSucceeded(AbstractStripeHubEvent):
next_invoice_date = next_invoice.get("period_end", 0)
data = dict(
canceled_at=subscription.get("canceled_at"),
cancel_at=subscription.get("cancel_at"),
cancel_at_period_end=subscription.get("cancel_at_period_end"),
current_period_start=subscription.get("current_period_start"),
current_period_end=subscription.get("current_period_end"),
next_invoice_date=next_invoice_date,
invoice_id=subscription.get("latest_invoice"),
active=self.payment_active_or_trialing(subscription.get("status")),
productName=product_name,
created=subscription.get("created"),
currency=plan.get("currency"),
invoice_number=invoice_number,
brand=brand,
last4=last4,
charge=charge_id,
Billing_Cycle_Start__c=subscription.get("current_period_start"),
Billing_Cycle_End__c=subscription.get("current_period_end"),
Next_Invoice_Date__c=next_invoice_date,
PMT_Invoice_ID__c=subscription.get("latest_invoice"),
CloseDate=subscription.get("created"),
Currency__c=plan.get("currency"),
Invoice_Number__c=invoice_number,
Credit_Card_Type__c=brand,
Last_4_Digits__c=last4,
PMT_Transaction_ID__c=charge_id,
)
if event_type == "customer.recurring_charge":
data.update(self.get_recurring_data(customer_id=customer.get("id")))