Skip to content
Open
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/recurly/recurly-client-go/v4

go 1.12
go 1.23
22 changes: 21 additions & 1 deletion payment_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,36 @@ package recurly

import (
"context"
"encoding/json"
"net/http"
"strings"
)

type tempCardType string

func (t *tempCardType) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err == nil {
*t = tempCardType(s)
return nil
} else if !strings.Contains(err.Error(), "cannot unmarshal object into Go value of type string") {
return err
}
// recurly is stupid
/*
{"visa":"Visa","sepa":"SEPA","master":"MasterCard","bancontact":"Bancontact","cartes_bancaires":"Cartes Bancaires","discover":"Discover","american_express":"American Express","diners_club":"Diners Club","jcb":"JCB","dankort":"Dankort","maestro":"Maestro","forbrugsforeningen":"Forbrugsforeningen","laser":"Laser","apple_pay":"Apple Pay","adyen_ach":"Adyen ACH","union_pay":"Union Pay","elo":"ELO","hipercard":"Hipercard","bogus":"Test Card","token":"Token","tarjeta_naranja":"Tarjeta Naranja","unknown":"Unknown"}
*/
*t = "Unknown Object"
return nil
}

type PaymentMethod struct {
recurlyResponse *ResponseMetadata

Object string `json:"object,omitempty"`

// Visa, MasterCard, American Express, Discover, JCB, etc.
CardType string `json:"card_type,omitempty"`
CardType tempCardType `json:"card_type,omitempty"`

// Credit card number's first six digits.
FirstSix string `json:"first_six,omitempty"`
Expand Down