<commit_before>package main

import (
	"encoding/json"
	"koding/kodingemail"
	"socialapi/workers/payment/paymentemail"
	"socialapi/workers/payment/paymentwebhook/webhookmodels"
	"socialapi/workers/payment/stripe"
)

func stripeSubscriptionCreated(raw []byte, email *kodingemail.SG) error {
	sub, err := _stripeSubscriptionHelper(raw)
	if err != nil {
		return err
	}

	return subscriptionEmail(
		sub.CustomerId, sub.Plan.Name, paymentemail.SubscriptionCreated, email,
	)
}

func stripeSubscriptionDeleted(raw []byte, email *kodingemail.SG) error {
	sub, err := _stripeSubscriptionHelper(raw)
	if err != nil {
		return err
	}

	err = stopMachinesForUser(sub.CustomerId)
	if err != nil {
		return err
	}

	err = stripe.SubscriptionDeletedWebhook(sub)
	if err != nil {
		return err
	}

	return subscriptionEmail(
		sub.CustomerId, sub.Plan.Name, paymentemail.SubscriptionDeleted, email,
	)
}

func _stripeSubscriptionHelper(raw []byte) (*webhookmodels.StripeSubscription, error) {
	var req *webhookmodels.StripeSubscription

	err := json.Unmarshal(raw, &req)
	if err != nil {
		return nil, err
	}

	return req, nil
}<commit_msg>paymentwebhook: minor format fix<commit_after>package main

import (
	"encoding/json"
	"koding/kodingemail"
	"socialapi/workers/payment/paymentemail"
	"socialapi/workers/payment/paymentwebhook/webhookmodels"
	"socialapi/workers/payment/stripe"
)

func stripeSubscriptionCreated(raw []byte, email *kodingemail.SG) error {
	sub, err := unmarshalSubscription(raw)
	if err != nil {
		return err
	}

	return subscriptionEmail(
		sub.CustomerId, sub.Plan.Name, paymentemail.SubscriptionCreated, email,
	)
}

func stripeSubscriptionDeleted(raw []byte, email *kodingemail.SG) error {
	sub, err := unmarshalSubscription(raw)
	if err != nil {
		return err
	}

	err = stopMachinesForUser(sub.CustomerId)
	if err != nil {
		return err
	}

	err = stripe.SubscriptionDeletedWebhook(sub)
	if err != nil {
		return err
	}

	return subscriptionEmail(
		sub.CustomerId, sub.Plan.Name, paymentemail.SubscriptionDeleted, email,
	)
}

func unmarshalSubscription(raw []byte) (*webhookmodels.StripeSubscription, error) {
	var req *webhookmodels.StripeSubscription

	err := json.Unmarshal(raw, &req)
	if err != nil {
		return nil, err
	}

	return req, nil
}
{'fraction_non_alphanumeric': 0.1111111111111111, 'fraction_numerical': 0.0, 'mean_word_length': 4.947368421052632, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6613038', 'n_tokens_mistral': 782, 'n_tokens_neox': 767, 'n_words': 167}