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

Feat: Add coupon property to payment request body #63

Merged
merged 1 commit into from
Jan 22, 2025
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ assessment, err := client.RegisterPayment(&incognia.Payment{
AccountID: "account-id",
ExternalID: "external-id",
PolicyID: "policy-id",
Coupon: &incognia.CouponType{
Type: "coupon-type", //it should be percent_off or fixed_value
Value: 55.02,
MaxDiscount: 30,
Id: "identifier",
Name: "coupon-name",
},
CustomProperties: myCustomPropertiesMap
Addresses: []*incognia.TransactionAddress{
{
Expand Down
2 changes: 2 additions & 0 deletions incognia.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Payment struct {
AccountID string
ExternalID string
PolicyID string
Coupon *CouponType
Addresses []*TransactionAddress
Value *PaymentValue
Methods []*PaymentMethod
Expand Down Expand Up @@ -290,6 +291,7 @@ func (c *Client) registerPayment(payment *Payment) (ret *TransactionAssessment,
Type: paymentType,
AccountID: payment.AccountID,
PolicyID: payment.PolicyID,
Coupon: payment.Coupon,
ExternalID: payment.ExternalID,
Addresses: payment.Addresses,
PaymentValue: payment.Value,
Expand Down
48 changes: 38 additions & 10 deletions incognia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,18 @@ var (
},
}
postPaymentRequestBodyFixture = &postTransactionRequestBody{
InstallationID: &installationId,
AccountID: "account-id",
ExternalID: "external-id",
PolicyID: "policy-id",
Type: paymentType,
InstallationID: &installationId,
AccountID: "account-id",
ExternalID: "external-id",
PolicyID: "policy-id",
Type: paymentType,
Coupon: &CouponType{
Type: "coupon_type",
Value: 55.02,
MaxDiscount: 30,
Id: "identifier",
Name: "CouponName",
},
CustomProperties: customProperty,
Addresses: []*TransactionAddress{
{
Expand Down Expand Up @@ -229,7 +236,14 @@ var (
AccountID: "account-id",
ExternalID: "external-id",
PolicyID: "policy-id",
Type: paymentType,
Coupon: &CouponType{
Type: "coupon_type",
Value: 55.02,
MaxDiscount: 30,
Id: "identifier",
Name: "CouponName",
},
Type: paymentType,
Addresses: []*TransactionAddress{
{
Type: Billing,
Expand Down Expand Up @@ -276,10 +290,17 @@ var (
Type: paymentType,
}
paymentFixture = &Payment{
InstallationID: &installationId,
AccountID: "account-id",
ExternalID: "external-id",
PolicyID: "policy-id",
InstallationID: &installationId,
AccountID: "account-id",
ExternalID: "external-id",
PolicyID: "policy-id",
Coupon: &CouponType{
Type: "coupon_type",
Value: 55.02,
MaxDiscount: 30,
Id: "identifier",
Name: "CouponName",
},
CustomProperties: customProperty,
Addresses: []*TransactionAddress{
{
Expand Down Expand Up @@ -326,6 +347,13 @@ var (
AccountID: "account-id",
ExternalID: "external-id",
PolicyID: "policy-id",
Coupon: &CouponType{
Type: "coupon_type",
Value: 55.02,
MaxDiscount: 30,
Id: "identifier",
Name: "CouponName",
},
Addresses: []*TransactionAddress{
{
Type: Billing,
Expand Down
9 changes: 9 additions & 0 deletions request_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ type PaymentValue struct {
Currency string `json:"currency"`
}

type CouponType struct {
Type string `json:"type"`
Value float64 `json:"value"`
MaxDiscount float64 `json:"max_discount"`
Id string `json:"id"`
Name string `json:"name"`
}

type paymentMethodType string

const (
Expand Down Expand Up @@ -136,6 +144,7 @@ type PaymentMethod struct {
type postTransactionRequestBody struct {
ExternalID string `json:"external_id,omitempty"`
PolicyID string `json:"policy_id,omitempty"`
Coupon *CouponType `json:"coupon,omitempty"`
InstallationID *string `json:"installation_id,omitempty"`
PaymentMethodIdentifier string `json:"payment_method_identifier,omitempty"`
Type transactionType `json:"type"`
Expand Down
Loading