Skip to content

Commit

Permalink
Merge pull request #135 from VictorAvelar/payment-method-specific-fields
Browse files Browse the repository at this point in the history
Payment method specific fields
  • Loading branch information
VictorAvelar authored May 31, 2021
2 parents 04ba719 + f6abd64 commit 0461c3f
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 156 deletions.
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ run:
@docker run --rm mollie-go:latest
.PHONY: run

ci-lint:
# colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
@golangci-lint run --out-format=tab --issues-exit-code=0 --sort-results --skip-dirs-use-default --tests=false --presets=bugs,complexity,format,performance,style,unused
.PHONY: ci-lint

pr-lint:
@golangci-lint run --issues-exit-code=0 --out-format=github-actions --new=true --sort-results --skip-dirs-use-default --tests=false --presets=bugs,complexity,format,performance,style,unused
.PHONY: pr-lint

ci-all-presets:
@golangci-lint run --out-format=tab --issues-exit-code=0 --sort-results --skip-dirs-use-default --tests=false --presets=bugs,comment,complexity,error,format,import,metalinter,module,performance,sql,style,test,unused
.PHONY: ci-all-presets

lint:
@go version

Expand Down
121 changes: 68 additions & 53 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -985,11 +985,11 @@ ListMethods describes a list of paginated payment methods.

```go
type ListPaymentOptions struct {
Limit int `url:"limit,omitempty"`
Include string `url:"include,omitempty"`
Embed string `url:"embed,omitempty"`
ProfileID string `url:"profileId,omitempty"`
From string `url:"from,omitempty"`
Limit int `url:"limit,omitempty"`
}
```

Expand Down Expand Up @@ -1848,51 +1848,67 @@ PaginationLinks describes the hal component of paginated responses.

```go
type Payment struct {
Resource string `json:"resource,omitempty"`
ID string `json:"id,omitempty"`
Mode Mode `json:"mode,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
Status string `json:"status,omitempty"`
IsCancellable bool `json:"isCancellable,omitempty"`
AuthorizedAt *time.Time `json:"authorizedAt,omitempty"`
PaidAt *time.Time `json:"paidAt,omitempty"`
CanceledAt *time.Time `json:"canceledAt,omitempty"`
ExpiresAt *time.Time `json:"expiresAt,omitempty"`
ExpiredAt *time.Time `json:"expiredAt,omitempty"`
FailedAt *time.Time `json:"failedAt,omitempty"`
Amount *Amount `json:"amount,omitempty"`
AmountRefunded *Amount `json:"amountRefunded,omitempty"`
AmountRemaining *Amount `json:"amountRemaining,omitempty"`
AmountCaptured *Amount `json:"amountCaptured,omitempty"`
Description string `json:"description,omitempty"`
RedirectURL string `json:"redirectUrl,omitempty"`
WebhookURL string `json:"webhookUrl,omitempty"`
Method PaymentMethod `json:"method,omitempty"`
Metadata interface{} `json:"metadata,omitempty"`
Locale Locale `json:"locale,omitempty"`
CountryCode string `json:"countryCode,omitempty"`
ProfileID string `json:"profileId,omitempty"`
SettlementAmount *Amount `json:"settlementAmount,omitempty"`
SettlementID string `json:"settlementId,omitempty"`
CustomerID string `json:"customerId,omitempty"`
SequenceType SequenceType `json:"sequenceType,omitempty"`
MandateID string `json:"mandateId,omitempty"`
OrderID string `json:"orderId,omitempty"`
ApplicationFee *ApplicationFee `json:"applicationFee,omitempty"`
Links PaymentLinks `json:"_links,omitempty"`
Details *PaymentDetails `json:"details,omitempty"`
RestrictPaymentMethodsToCountry Locale `json:"restrictPaymentMethodsToCountry,omitempty"`
SubscriptionID string `json:"subscriptionId,omitempty"`
TestMode bool `json:"testmode,omitempty"`
}
```

Payment describes a transaction between a customer and a merchant
IsCancellable bool `json:"isCancellable,omitempty"`
TestMode bool `json:"testmode,omitempty"`
DigitalGoods bool `json:"digitalGoods,omitempty"`
ApplePayPaymentToken string `json:"applePayPaymentToken,omitempty"`
BillingEmail string `json:"billingEmail,omitempty"`
CardToken string `json:"cardToken,omitempty"`
Issuer string `json:"issuer,omitempty"`
VoucherNumber string `json:"voucherNumber,omitempty"`
VoucherPin string `json:"voucherPin,omitempty"`
ExtraMerchantData string `json:"extraMerchantData,omitempty"`
SessionID string `json:"sessionId,omitempty"`
CustomerReference string `json:"customerReference,omitempty"`
ConsumerName string `json:"consumerName,omitempty"`
ConsumerAccount string `json:"consumerAccount,omitempty"`
WebhookURL string `json:"webhookUrl,omitempty"`
Resource string `json:"resource,omitempty"`
ID string `json:"id,omitempty"`
MandateID string `json:"mandateId,omitempty"`
OrderID string `json:"orderId,omitempty"`
ProfileID string `json:"profileId,omitempty"`
SettlementID string `json:"settlementId,omitempty"`
CustomerID string `json:"customerId,omitempty"`
Status string `json:"status,omitempty"`
Description string `json:"description,omitempty"`
RedirectURL string `json:"redirectUrl,omitempty"`
CountryCode string `json:"countryCode,omitempty"`
SubscriptionID string `json:"subscriptionId,omitempty"`
Metadata interface{} `json:"metadata,omitempty"`
Amount *Amount `json:"amount,omitempty"`
AmountRefunded *Amount `json:"amountRefunded,omitempty"`
AmountRemaining *Amount `json:"amountRemaining,omitempty"`
AmountCaptured *Amount `json:"amountCaptured,omitempty"`
SettlementAmount *Amount `json:"settlementAmount,omitempty"`
ApplicationFee *ApplicationFee `json:"applicationFee,omitempty"`
Details *PaymentDetails `json:"details,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
AuthorizedAt *time.Time `json:"authorizedAt,omitempty"`
PaidAt *time.Time `json:"paidAt,omitempty"`
CanceledAt *time.Time `json:"canceledAt,omitempty"`
ExpiresAt *time.Time `json:"expiresAt,omitempty"`
ExpiredAt *time.Time `json:"expiredAt,omitempty"`
FailedAt *time.Time `json:"failedAt,omitempty"`
DueDate *ShortDate `json:"dueDate,omitempty"`
BillingAddress *Address `json:"billingAddress,omitempty"`
ShippingAddress *PaymentDetailsAddress `json:"shippingAddress,omitempty"`
Mode Mode `json:"mode,omitempty"`
Locale Locale `json:"locale,omitempty"`
RestrictPaymentMethodsToCountry Locale `json:"restrictPaymentMethodsToCountry,omitempty"`
Method PaymentMethod `json:"method,omitempty"`
Links PaymentLinks `json:"_links,omitempty"`
SequenceType SequenceType `json:"sequenceType,omitempty"`
}
```

Payment describes a transaction between a customer and a merchant.

#### type PaymentDetails

```go
type PaymentDetails struct {
PaypalDigitalGoods bool `json:"digitalGoods,omitempty"`
BankAccount string `json:"bankAccount,omitempty"`
BankBIC string `json:"bankBic,omitempty"`
BankName string `json:"bankName,omitempty"`
Expand All @@ -1911,26 +1927,25 @@ type PaymentDetails struct {
ConsumerName string `json:"consumerName,omitempty"`
ConsumerReference string `json:"consumerReference,omitempty"`
CreditorIdentifier string `json:"creditorIdentifier,omitempty"`
DueDate *ShortDate `json:"dueDate,omitempty"`
EndToEndIdentifier string `json:"endToEndIdentifier,omitempty"`
FailureReason FailureReason `json:"failureReason,omitempty"`
FeeRegion FeeRegion `json:"feeRegion,omitempty"`
FileReference string `json:"fileReference,omitempty"`
GiftCards []*UsedGiftCard `json:"giftCards,omitempty"`
MandateReference string `json:"mandateReference,omitempty"`
PaypalDigitalGoods bool `json:"digitalGoods,omitempty"`
PaypalFee Amount `json:"paypalFee,omitempty"`
PaypalPayerID string `json:"paypalPayerId,omitempty"`
PaypalReference string `json:"paypalReference,omitempty"`
QRCode *QRCode `json:"qrCode,omitempty"`
RemainderAmount *Amount `json:"remainderAmount,omitempty"`
PaypalPayerID string `json:"paypalPayerId,omitempty"`
TransferReference string `json:"transferReference,omitempty"`
VoucherNumber string `json:"voucherNumber,omitempty"`
Wallet string `json:"wallet,omitempty"`
PaypalFee Amount `json:"paypalFee,omitempty"`
FailureReason FailureReason `json:"failureReason,omitempty"`
FeeRegion FeeRegion `json:"feeRegion,omitempty"`
RemainderMethod PaymentMethod `json:"remainderMethod,omitempty"`
SellerProtection EligibilityReasons `json:"sellerProtection,omitempty"`
DueDate *ShortDate `json:"dueDate,omitempty"`
GiftCards []*UsedGiftCard `json:"giftCards,omitempty"`
QRCode *QRCode `json:"qrCode,omitempty"`
RemainderAmount *Amount `json:"remainderAmount,omitempty"`
ShippingAddress *PaymentDetailsAddress `json:"shippingAddress,omitempty"`
SignatureDate *ShortDate `json:"signatureDate,omitempty"`
TransferReference string `json:"transferReference,omitempty"`
VoucherNumber string `json:"voucherNumber,omitempty"`
Wallet string `json:"wallet,omitempty"`
Links struct {
Status *URL `json:"status,omitempty"`
PayOnline *URL `json:"payOnline,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ go 1.15

require (
github.com/google/go-querystring v1.1.0
golang.org/x/oauth2 v0.0.0-20210413134643-5e61552d6c78
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4Iltr
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20210413134643-5e61552d6c78 h1:rPRtHfUb0UKZeZ6GH4K4Nt4YRbE9V1u+QZX5upZXqJQ=
golang.org/x/oauth2 v0.0.0-20210413134643-5e61552d6c78/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c h1:pkQiBZBvdos9qq4wBAHqlzuZHEXo07pqV06ef90u1WI=
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
49 changes: 0 additions & 49 deletions mollie/mollie_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package mollie

import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"os"
"reflect"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -386,50 +383,4 @@ func testHeader(t *testing.T, r *http.Request, header string, want string) {
}
}

func testURLParseError(t *testing.T, err error) {
if err == nil {
t.Errorf("Expected error to be returned")
}
if err, ok := err.(*url.Error); !ok || err.Op != "parse" {
t.Errorf("Expected URL parse error, got %+v", err)
}
}

func testBody(t *testing.T, r *http.Request, want string) {
b, err := ioutil.ReadAll(r.Body)
if err != nil {
t.Errorf("Error reading request body: %v", err)
}
if got := string(b); got != want {
t.Errorf("request Body is %s, want %s", got, want)
}
}

func testJSONMarshal(t *testing.T, v interface{}, want string) {
j, err := json.Marshal(v)
if err != nil {
t.Errorf("Unable to marshal JSON for %v", v)
}

w := new(bytes.Buffer)
err = json.Compact(w, []byte(want))
if err != nil {
t.Errorf("String is not valid json: %s", want)
}

if w.String() != string(j) {
t.Errorf("json.Marshal(%q) returned %s, want %s", v, j, w)
}

// now go the other direction and make sure things unmarshal as expected
u := reflect.ValueOf(v).Interface()
if err := json.Unmarshal([]byte(want), u); err != nil {
t.Errorf("Unable to unmarshal JSON for %v: %v", want, err)
}

if !reflect.DeepEqual(v, u) {
t.Errorf("json.Unmarshal(%q) returned %s, want %s", want, u, v)
}
}

// <----- .Testing helpers ----->
1 change: 0 additions & 1 deletion mollie/onboarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func TestOnboardingService_SubmitOnboardingData(t *testing.T) {
}

rw.WriteHeader(http.StatusCreated)
return
})

od := OnboardingData{}
Expand Down
24 changes: 12 additions & 12 deletions mollie/payment_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type UsedGiftCard struct {

// PaymentDetails contains details for the specified payment method
type PaymentDetails struct {
PaypalDigitalGoods bool `json:"digitalGoods,omitempty"`
BankAccount string `json:"bankAccount,omitempty"`
BankBIC string `json:"bankBic,omitempty"`
BankName string `json:"bankName,omitempty"`
Expand All @@ -72,26 +73,25 @@ type PaymentDetails struct {
ConsumerName string `json:"consumerName,omitempty"`
ConsumerReference string `json:"consumerReference,omitempty"`
CreditorIdentifier string `json:"creditorIdentifier,omitempty"`
DueDate *ShortDate `json:"dueDate,omitempty"`
EndToEndIdentifier string `json:"endToEndIdentifier,omitempty"`
FailureReason FailureReason `json:"failureReason,omitempty"`
FeeRegion FeeRegion `json:"feeRegion,omitempty"`
FileReference string `json:"fileReference,omitempty"`
GiftCards []*UsedGiftCard `json:"giftCards,omitempty"`
MandateReference string `json:"mandateReference,omitempty"`
PaypalDigitalGoods bool `json:"digitalGoods,omitempty"`
PaypalFee Amount `json:"paypalFee,omitempty"`
PaypalPayerID string `json:"paypalPayerId,omitempty"`
PaypalReference string `json:"paypalReference,omitempty"`
QRCode *QRCode `json:"qrCode,omitempty"`
RemainderAmount *Amount `json:"remainderAmount,omitempty"`
PaypalPayerID string `json:"paypalPayerId,omitempty"`
TransferReference string `json:"transferReference,omitempty"`
VoucherNumber string `json:"voucherNumber,omitempty"`
Wallet string `json:"wallet,omitempty"`
PaypalFee Amount `json:"paypalFee,omitempty"`
FailureReason FailureReason `json:"failureReason,omitempty"`
FeeRegion FeeRegion `json:"feeRegion,omitempty"`
RemainderMethod PaymentMethod `json:"remainderMethod,omitempty"`
SellerProtection EligibilityReasons `json:"sellerProtection,omitempty"`
DueDate *ShortDate `json:"dueDate,omitempty"`
GiftCards []*UsedGiftCard `json:"giftCards,omitempty"`
QRCode *QRCode `json:"qrCode,omitempty"`
RemainderAmount *Amount `json:"remainderAmount,omitempty"`
ShippingAddress *PaymentDetailsAddress `json:"shippingAddress,omitempty"`
SignatureDate *ShortDate `json:"signatureDate,omitempty"`
TransferReference string `json:"transferReference,omitempty"`
VoucherNumber string `json:"voucherNumber,omitempty"`
Wallet string `json:"wallet,omitempty"`
Links struct {
Status *URL `json:"status,omitempty"`
PayOnline *URL `json:"payOnline,omitempty"`
Expand Down
Loading

0 comments on commit 0461c3f

Please sign in to comment.