Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production 2024-02-14_01 #2350

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
210 changes: 92 additions & 118 deletions services/skus/controllers.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion services/skus/controllers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func (suite *ControllersTestSuite) TestIOSWebhookCertFail() {
err := suite.service.Datastore.AppendOrderMetadata(context.Background(), &order.ID, "externalID", "my external id")
suite.Require().NoError(err)

handler := HandleIOSWebhook(suite.service)
handler := handleIOSWebhook(suite.service)

// create a jws message to send
body := []byte{}
Expand Down
7 changes: 0 additions & 7 deletions services/skus/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,8 @@ type IOSNotification struct {

// Decode - implement Decodable interface
func (iosn *IOSNotification) Decode(ctx context.Context, data []byte) error {
logger := logging.Logger(ctx, "IOSNotification.Decode")
logger.Debug().Msg("starting IOSNotification.Decode")

// json unmarshal the notification
if err := json.Unmarshal(data, iosn); err != nil {
logger.Error().Msg("failed to json unmarshal body")
return errorutils.Wrap(err, "error unmarshalling body")
}

Expand All @@ -266,8 +262,6 @@ func (iosn *IOSNotification) Decode(ctx context.Context, data []byte) error {

// Validate - implement Validable interface
func (iosn *IOSNotification) Validate(ctx context.Context) error {
logger := logging.Logger(ctx, "IOSNotification.Validate")

// extract the public key from the jws
pk, err := extractPublicKey(iosn.SignedPayload)
if err != nil {
Expand All @@ -278,7 +272,6 @@ func (iosn *IOSNotification) Validate(ctx context.Context) error {
if err != nil {
return fmt.Errorf("failed to verify jws payload in request: %w", err)
}
logger.Debug().Msg("validated ios notification")

iosn.payload = payload

Expand Down
55 changes: 53 additions & 2 deletions services/skus/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ const (
)

const (
VendorApple Vendor = "ios"
VendorGoogle Vendor = "android"
VendorUnknown Vendor = "unknown"
VendorApple Vendor = "ios"
VendorGoogle Vendor = "android"
)

var (
Expand Down Expand Up @@ -145,6 +146,7 @@ func CreateStripeCheckoutSession(
}

params := &stripe.CheckoutSessionParams{
// TODO: Get rid of this stripe.* nonsense, and use ptrTo instead.
PaymentMethodTypes: stripe.StringSlice([]string{"card"}),
Mode: stripe.String(string(stripe.CheckoutSessionModeSubscription)),
SuccessURL: stripe.String(successURI),
Expand Down Expand Up @@ -318,6 +320,55 @@ func (o *Order) HasItem(id uuid.UUID) (*OrderItem, bool) {
return nil, false
}

func (o *Order) StripeSubID() (string, bool) {
sid, ok := o.Metadata["stripeSubscriptionId"].(string)

return sid, ok
}

func (o *Order) IsIOS() bool {
pp, ok := o.PaymentProc()
if !ok {
return false
}

vn, ok := o.Vendor()
if !ok {
return false
}

return pp == "ios" && vn == VendorApple
}

func (o *Order) IsAndroid() bool {
pp, ok := o.PaymentProc()
if !ok {
return false
}

vn, ok := o.Vendor()
if !ok {
return false
}

return pp == "android" && vn == VendorGoogle
}

func (o *Order) PaymentProc() (string, bool) {
pp, ok := o.Metadata["paymentProcessor"].(string)

return pp, ok
}

func (o *Order) Vendor() (Vendor, bool) {
vn, ok := o.Metadata["vendor"].(string)
if !ok {
return VendorUnknown, false
}

return Vendor(vn), true
}

// OrderItem represents a particular order item.
type OrderItem struct {
ID uuid.UUID `json:"id" db:"id"`
Expand Down
Loading
Loading