Skip to content

Commit

Permalink
Add fix for payment method is string
Browse files Browse the repository at this point in the history
  • Loading branch information
Denys Misko committed Nov 13, 2024
1 parent 95e8f31 commit e432edf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
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

0 comments on commit e432edf

Please sign in to comment.