Skip to content

Commit

Permalink
Merge pull request #2350 from brave-intl/master
Browse files Browse the repository at this point in the history
Production 2024-02-14_01
  • Loading branch information
pavelbrm authored Feb 14, 2024
2 parents 805eba8 + 74f7ac2 commit 68a0650
Show file tree
Hide file tree
Showing 8 changed files with 790 additions and 179 deletions.
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

0 comments on commit 68a0650

Please sign in to comment.