-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from sarmadka/main
Added support for fetching promo codes.
- Loading branch information
Showing
11 changed files
with
351 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
@merge module Stripe { | ||
func getPromotionCodes(key: String, code: String, verbose: Bool): Possible[Array[SrdRef[PromotionCode]]] { | ||
return getRecords[PromotionCode, convertToPromotionCode]( | ||
key, String("https://api.stripe.com/v1/promotion_codes?code=") + code, -1, String(), verbose | ||
); | ||
} | ||
|
||
func convertToPromotionCode(promotionCodeJson: Json): SrdRef[PromotionCode] { | ||
return SrdRef[PromotionCode]().{ | ||
alloc()~init( | ||
promotionCodeJson("id"), | ||
promotionCodeJson("active"), | ||
promotionCodeJson("code"), | ||
promotionCodeJson("livemode"), | ||
convertToCoupon(promotionCodeJson("coupon")) | ||
) | ||
}; | ||
} | ||
|
||
func convertToCoupon(couponJson: Json): SrdRef[Coupon] { | ||
return SrdRef[Coupon]().{ | ||
alloc()~init( | ||
couponJson("id"), | ||
couponJson("name"), | ||
couponJson("duration"), | ||
couponJson("duration_in_months"), | ||
couponJson("amount_off"), | ||
couponJson("percent_off"), | ||
couponJson("currency") | ||
) | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
@merge module Stripe { | ||
class Coupon { | ||
def id: String; | ||
def name: Nullable[String]; | ||
def duration: String; | ||
def durationInMonths: Nullable[String]; | ||
def amountOff: Nullable[Int]; | ||
def percentOff: Nullable[Float]; | ||
def currency: Nullable[String]; | ||
|
||
handler this~init() {} | ||
|
||
handler this~init( | ||
id: String, | ||
name: Nullable[String], | ||
duration: String, | ||
durationInMonths: Nullable[String], | ||
amountOff: Nullable[Int], | ||
percentOff: Nullable[Float], | ||
currency: Nullable[String] | ||
) { | ||
this.id = id; | ||
this.name = name; | ||
this.duration = duration; | ||
this.durationInMonths = durationInMonths; | ||
this.amountOff = amountOff; | ||
this.percentOff = percentOff; | ||
this.currency = currency; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
@merge module Stripe { | ||
class PromotionCode { | ||
def id: String; | ||
def active: Bool; | ||
def code: String; | ||
def livemode: Bool; | ||
def coupon: SrdRef[Coupon]; | ||
|
||
handler this~init() {} | ||
|
||
handler this~init( | ||
id: String, | ||
active: Bool, | ||
code: String, | ||
livemode: Bool, | ||
coupon: SrdRef[Coupon] | ||
) { | ||
this.id = id; | ||
this.active = active; | ||
this.code = code; | ||
this.livemode = livemode; | ||
this.coupon = coupon; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.