-
Notifications
You must be signed in to change notification settings - Fork 463
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 #986 from stripe/remi-add-mandate
Adding support for iDEAL and SEPA debit on PaymentMethod
- Loading branch information
Showing
9 changed files
with
273 additions
and
5 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
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,119 @@ | ||
package stripe | ||
|
||
import "encoding/json" | ||
|
||
// List of values that MandateStatus can take. | ||
const ( | ||
MandateCustomerAcceptanceTypeOffline MandateCustomerAcceptanceType = "offline" | ||
MandateCustomerAcceptanceTypeOnline MandateCustomerAcceptanceType = "online" | ||
) | ||
|
||
// MandateCustomerAcceptanceType is the list of allowed values for the type of customer acceptance | ||
// for a given mandate.. | ||
type MandateCustomerAcceptanceType string | ||
|
||
// List of values that MandateStatus can take. | ||
const ( | ||
MandateStatusActive MandateStatus = "active" | ||
MandateStatusInactive MandateStatus = "inactive" | ||
MandateStatusPending MandateStatus = "pending" | ||
) | ||
|
||
// MandateStatus is the list of allowed values for the mandate status. | ||
type MandateStatus string | ||
|
||
// List of values that MandateType can take. | ||
const ( | ||
MandateTypeMultiUse MandateType = "multi_use" | ||
MandateTypeSingleUse MandateType = "single_use" | ||
) | ||
|
||
// MandateType is the list of allowed values for the mandate type. | ||
type MandateType string | ||
|
||
// MandateParams is the set of parameters that can be used when retrieving a mandate. | ||
type MandateParams struct { | ||
Params `form:"*"` | ||
} | ||
|
||
// MandateCustomerAcceptanceOffline represents details about the customer acceptance of an offline | ||
// mandate. | ||
type MandateCustomerAcceptanceOffline struct { | ||
} | ||
|
||
// MandateCustomerAcceptanceOnline represents details about the customer acceptance of an online | ||
// mandate. | ||
type MandateCustomerAcceptanceOnline struct { | ||
IPAddress string `json:"ip_address"` | ||
UserAgent string `json:"user_agent"` | ||
} | ||
|
||
// MandateCustomerAcceptance represents details about the customer acceptance for a mandate. | ||
type MandateCustomerAcceptance struct { | ||
AcceptedAt int64 `json:"accepted_at"` | ||
Offline *MandateCustomerAcceptanceOffline `json:"offline"` | ||
Online *MandateCustomerAcceptanceOnline `json:"online"` | ||
Type MandateCustomerAcceptanceType `json:"type"` | ||
} | ||
|
||
// MandateMultiUse represents details about a multi-use mandate. | ||
type MandateMultiUse struct { | ||
} | ||
|
||
// MandatePaymentMethodDetailsCard represents details about the card associated with this mandate. | ||
type MandatePaymentMethodDetailsCard struct { | ||
} | ||
|
||
// MandatePaymentMethodDetailsSepaDebit represents details about the SEPA debit bank account | ||
// associated with this mandate. | ||
type MandatePaymentMethodDetailsSepaDebit struct { | ||
Reference string `json:"reference"` | ||
URL string `json:"url"` | ||
} | ||
|
||
// MandatePaymentMethodDetails represents details about the payment method associated with this | ||
// mandate. | ||
type MandatePaymentMethodDetails struct { | ||
Card *MandatePaymentMethodDetailsCard `json:"card"` | ||
SepaDebit *MandatePaymentMethodDetailsSepaDebit `json:"sepa_debit"` | ||
Type PaymentMethodType `json:"type"` | ||
} | ||
|
||
// MandateSingleUse represents details about a single-use mandate. | ||
type MandateSingleUse struct { | ||
Amount int64 `json:"amount"` | ||
Currency Currency `json:"currency"` | ||
} | ||
|
||
// Mandate is the resource representing a Mandate. | ||
type Mandate struct { | ||
CustomerAcceptance *MandateCustomerAcceptance `json:"customer_acceptance"` | ||
ID string `json:"id"` | ||
Livemode bool `json:"livemode"` | ||
MultiUse *MandateMultiUse `json:"multi_use"` | ||
Object string `json:"object"` | ||
PaymentMethod *PaymentMethod `json:"payment_method"` | ||
PaymentMethodDetails *MandatePaymentMethodDetails `json:"payment_method_details"` | ||
SingleUse *MandateSingleUse `json:"single_use"` | ||
Status MandateStatus `json:"status"` | ||
Type MandateType `json:"type"` | ||
} | ||
|
||
// UnmarshalJSON handles deserialization of a Mandate. | ||
// This custom unmarshaling is needed because the resulting | ||
// property may be an id or the full struct if it was expanded. | ||
func (i *Mandate) UnmarshalJSON(data []byte) error { | ||
if id, ok := ParseID(data); ok { | ||
i.ID = id | ||
return nil | ||
} | ||
|
||
type ma Mandate | ||
var v ma | ||
if err := json.Unmarshal(data, &v); err != nil { | ||
return err | ||
} | ||
|
||
*i = Mandate(v) | ||
return nil | ||
} |
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 @@ | ||
// Package mandate provides the /mandates APIs | ||
package mandate | ||
|
||
import ( | ||
"net/http" | ||
|
||
stripe "github.com/stripe/stripe-go" | ||
) | ||
|
||
// Client is used to invoke mandates APIs. | ||
type Client struct { | ||
B stripe.Backend | ||
Key string | ||
} | ||
|
||
// Get returns the details of a Mandate. | ||
func Get(id string, params *stripe.MandateParams) (*stripe.Mandate, error) { | ||
return getC().Get(id, params) | ||
} | ||
|
||
// Get returns the details of a Mandate. | ||
func (c Client) Get(id string, params *stripe.MandateParams) (*stripe.Mandate, error) { | ||
path := stripe.FormatURLPath("/v1/mandates/%s", id) | ||
mandate := &stripe.Mandate{} | ||
err := c.B.Call(http.MethodGet, path, c.Key, params, mandate) | ||
return mandate, err | ||
} | ||
|
||
func getC() Client { | ||
return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} | ||
} |
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,14 @@ | ||
package mandate | ||
|
||
import ( | ||
"testing" | ||
|
||
assert "github.com/stretchr/testify/require" | ||
_ "github.com/stripe/stripe-go/testing" | ||
) | ||
|
||
func TestMandateMethodGet(t *testing.T) { | ||
pm, err := Get("mandate_123", nil) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, pm) | ||
} |
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.