Skip to content

Commit

Permalink
Add support for installments on PaymentIntent and Charge
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Oct 23, 2019
1 parent 4990b62 commit c701a47
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 36 deletions.
7 changes: 7 additions & 0 deletions charge.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ type ChargePaymentMethodDetailsCardChecks struct {
CVCCheck CardVerification `json:"cvc_check"`
}

// ChargePaymentMethodDetailsCardInstallments represents details about the installment plan chosen
// for this charge.
type ChargePaymentMethodDetailsCardInstallments struct {
Plan *PaymentIntentPaymentMethodOptionsCardInstallmentsPlan `json:"plan"`
}

// ChargePaymentMethodDetailsCardThreeDSecure represents details about 3DS associated with the
// charge's PaymentMethod.
type ChargePaymentMethodDetailsCardThreeDSecure struct {
Expand Down Expand Up @@ -303,6 +309,7 @@ type ChargePaymentMethodDetailsCard struct {
ExpYear uint64 `json:"exp_year"`
Fingerprint string `json:"fingerprint"`
Funding CardFunding `json:"funding"`
Installments *ChargePaymentMethodDetailsCardInstallments `json:"installments"`
Last4 string `json:"last4"`
MOTO bool `json:"moto"`
ThreeDSecure *ChargePaymentMethodDetailsCardThreeDSecure `json:"three_d_secure"`
Expand Down
133 changes: 97 additions & 36 deletions paymentintent.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ const (
PaymentIntentPaymentMethodOptionsCardRequestThreeDSecureChallengeOnly PaymentIntentPaymentMethodOptionsCardRequestThreeDSecure = "challenge_only"
)

// PaymentIntentPaymentMethodOptionsCardInstallmentsPlanInterval is the interval of a card installment plan.
type PaymentIntentPaymentMethodOptionsCardInstallmentsPlanInterval string

// List of values that PaymentIntentNextActionType can take.
const (
PaymentIntentPaymentMethodOptionsCardInstallmentsPlanIntervalMonth PaymentIntentPaymentMethodOptionsCardInstallmentsPlanInterval = "month"
)

// PaymentIntentPaymentMethodOptionsCardInstallmentsPlanType is the type of a card installment plan.
type PaymentIntentPaymentMethodOptionsCardInstallmentsPlanType string

// List of values that PaymentIntentNextActionType can take.
const (
PaymentIntentPaymentMethodOptionsCardInstallmentsPlanTypeFixedCount PaymentIntentPaymentMethodOptionsCardInstallmentsPlanType = "fixed_count"
)

// PaymentIntentSetupFutureUsage is the list of allowed values for SetupFutureUsage.
type PaymentIntentSetupFutureUsage string

Expand Down Expand Up @@ -120,11 +136,27 @@ type PaymentIntentConfirmParams struct {
Source *string `form:"source"`
}

// PaymentIntentPaymentMethodOptionsCardInstallmentsPlanParams represents details about the
// installment plan chosen for this payment intent.
type PaymentIntentPaymentMethodOptionsCardInstallmentsPlanParams struct {
Count *int64 `form:"count"`
Interval *string `form:"interval"`
Plan *string `form:"type"`
}

// PaymentIntentPaymentMethodOptionsCardInstallmentsParams controls whether to enable installment
// plans for this payment intent.
type PaymentIntentPaymentMethodOptionsCardInstallmentsParams struct {
Enabled *bool `form:"enabled"`
Plan *PaymentIntentPaymentMethodOptionsCardInstallmentsPlanParams `form:"plan"`
}

// PaymentIntentPaymentMethodOptionsCardParams represents the card-specific options applied to a
// PaymentIntent.
type PaymentIntentPaymentMethodOptionsCardParams struct {
MOTO *bool `form:"moto"`
RequestThreeDSecure *string `form:"request_three_d_secure"`
Installments *PaymentIntentPaymentMethodOptionsCardInstallmentsParams `form:"installments"`
MOTO *bool `form:"moto"`
RequestThreeDSecure *string `form:"request_three_d_secure"`
}

// PaymentIntentPaymentMethodOptionsParams represents the type-specific payment method options
Expand Down Expand Up @@ -191,6 +223,34 @@ type PaymentIntentNextAction struct {
Type PaymentIntentNextActionType `json:"type"`
}

// PaymentIntentPaymentMethodOptionsCardInstallmentsPlan describe a specific card installment plan.
type PaymentIntentPaymentMethodOptionsCardInstallmentsPlan struct {
Count int64 `json:"count"`
Interval PaymentIntentPaymentMethodOptionsCardInstallmentsPlanInterval `json:"interval"`
Type PaymentIntentPaymentMethodOptionsCardInstallmentsPlanType `json:"type"`
}

// PaymentIntentPaymentMethodOptionsCardInstallments describe the installment options available for
// a card associated with that payment intent.
type PaymentIntentPaymentMethodOptionsCardInstallments struct {
AvailablePlans []*PaymentIntentPaymentMethodOptionsCardInstallmentsPlan `json:"available_plans"`
Enaled bool `json:"enabled"`
Plan *PaymentIntentPaymentMethodOptionsCardInstallmentsPlan `json:"plan"`
}

// PaymentIntentPaymentMethodOptionsCard is the set of card-specific options associated with that
// payment intent.
type PaymentIntentPaymentMethodOptionsCard struct {
Installments *PaymentIntentPaymentMethodOptionsCardInstallments `json:"installments"`
RequestThreeDSecure PaymentIntentPaymentMethodOptionsCardRequestThreeDSecure `json:"request_three_d_secure"`
}

// PaymentIntentPaymentMethodOptions is the set of payment method-specific options associated with
// that payment intent.
type PaymentIntentPaymentMethodOptions struct {
Card *PaymentIntentPaymentMethodOptionsCard `json:"card"`
}

// PaymentIntentTransferData represents the information for the transfer associated with a payment intent.
type PaymentIntentTransferData struct {
Amount int64 `json:"amount"`
Expand All @@ -200,40 +260,41 @@ type PaymentIntentTransferData struct {
// PaymentIntent is the resource representing a Stripe payout.
// For more details see https://stripe.com/docs/api#payment_intents.
type PaymentIntent struct {
Amount int64 `json:"amount"`
AmountCapturable int64 `json:"amount_capturable"`
AmountReceived int64 `json:"amount_received"`
Application *Application `json:"application"`
ApplicationFeeAmount int64 `json:"application_fee_amount"`
CanceledAt int64 `json:"canceled_at"`
CancellationReason PaymentIntentCancellationReason `json:"cancellation_reason"`
CaptureMethod PaymentIntentCaptureMethod `json:"capture_method"`
Charges *ChargeList `json:"charges"`
ClientSecret string `json:"client_secret"`
ConfirmationMethod PaymentIntentConfirmationMethod `json:"confirmation_method"`
Created int64 `json:"created"`
Currency string `json:"currency"`
Customer *Customer `json:"customer"`
Description string `json:"description"`
Invoice *Invoice `json:"invoice"`
LastPaymentError *Error `json:"last_payment_error"`
Livemode bool `json:"livemode"`
ID string `json:"id"`
Metadata map[string]string `json:"metadata"`
NextAction *PaymentIntentNextAction `json:"next_action"`
OnBehalfOf *Account `json:"on_behalf_of"`
PaymentMethod *PaymentMethod `json:"payment_method"`
PaymentMethodTypes []string `json:"payment_method_types"`
ReceiptEmail string `json:"receipt_email"`
Review *Review `json:"review"`
SetupFutureUsage PaymentIntentSetupFutureUsage `json:"setup_future_usage"`
Shipping ShippingDetails `json:"shipping"`
Source *PaymentSource `json:"source"`
StatementDescriptor string `json:"statement_descriptor"`
StatementDescriptorSuffix string `json:"statement_descriptor_suffix"`
Status PaymentIntentStatus `json:"status"`
TransferData *PaymentIntentTransferData `json:"transfer_data"`
TransferGroup string `json:"transfer_group"`
Amount int64 `json:"amount"`
AmountCapturable int64 `json:"amount_capturable"`
AmountReceived int64 `json:"amount_received"`
Application *Application `json:"application"`
ApplicationFeeAmount int64 `json:"application_fee_amount"`
CanceledAt int64 `json:"canceled_at"`
CancellationReason PaymentIntentCancellationReason `json:"cancellation_reason"`
CaptureMethod PaymentIntentCaptureMethod `json:"capture_method"`
Charges *ChargeList `json:"charges"`
ClientSecret string `json:"client_secret"`
ConfirmationMethod PaymentIntentConfirmationMethod `json:"confirmation_method"`
Created int64 `json:"created"`
Currency string `json:"currency"`
Customer *Customer `json:"customer"`
Description string `json:"description"`
Invoice *Invoice `json:"invoice"`
LastPaymentError *Error `json:"last_payment_error"`
Livemode bool `json:"livemode"`
ID string `json:"id"`
Metadata map[string]string `json:"metadata"`
NextAction *PaymentIntentNextAction `json:"next_action"`
OnBehalfOf *Account `json:"on_behalf_of"`
PaymentMethod *PaymentMethod `json:"payment_method"`
PaymentMethodOptions *PaymentIntentPaymentMethodOptions `json:"payment_method_options"`
PaymentMethodTypes []string `json:"payment_method_types"`
ReceiptEmail string `json:"receipt_email"`
Review *Review `json:"review"`
SetupFutureUsage PaymentIntentSetupFutureUsage `json:"setup_future_usage"`
Shipping ShippingDetails `json:"shipping"`
Source *PaymentSource `json:"source"`
StatementDescriptor string `json:"statement_descriptor"`
StatementDescriptorSuffix string `json:"statement_descriptor_suffix"`
Status PaymentIntentStatus `json:"status"`
TransferData *PaymentIntentTransferData `json:"transfer_data"`
TransferGroup string `json:"transfer_group"`
}

// PaymentIntentList is a list of payment intents as retrieved from a list endpoint.
Expand Down

0 comments on commit c701a47

Please sign in to comment.