diff --git a/authorization.go b/authorization.go index 5786599..28b005f 100644 --- a/authorization.go +++ b/authorization.go @@ -16,10 +16,10 @@ type AuthorizationClient struct { type Authorization struct { ID string `json:"id"` Result Result `json:"result"` - Amount float64 `json:"amount"` + Amount int64 `json:"amount"` Created json.Number `json:"created"` ReconciliationID string `json:"reconciliation_id"` - PaymentMethod PaymentMethod `json:"payment_method"` + PaymentMethod PaymentMethodHref `json:"payment_method"` ThreeDSecureAttributes *ThreeDSecureAttributes `json:"three_d_secure_attributes"` Installments *Installments `json:"installments"` ProviderData ProviderData `json:"provider_data"` @@ -31,8 +31,7 @@ type Authorization struct { // AuthorizationParams is a set of params for creating entity. type AuthorizationParams struct { - PaymentMethodToken string `json:"payment_method_token"` - CreditCardCvv string `json:"credit_card_cvv,omitempty"` + PaymentMethod PaymentMethodDetails `json:"payment_method"` MerchantSiteURL string `json:"merchant_site_url,omitempty"` ReconciliationID string `json:"reconciliation_id,omitempty"` ThreeDSecureAttributes *ThreeDSecureAttributes `json:"three_d_secure_attributes,omitempty"` diff --git a/authorization_test.go b/authorization_test.go index 602a243..2b4e070 100644 --- a/authorization_test.go +++ b/authorization_test.go @@ -16,7 +16,10 @@ func TestAuthorizationClient_New(t *testing.T) { headerClientUserAgent: "ua", }, expectedReqObj: &AuthorizationParams{ - PaymentMethodToken: "token", + PaymentMethod: PaymentMethodDetails{ + Type: "tokenized", + Token: "token", + }, }, returnRespObj: &Authorization{ ID: "id", @@ -30,7 +33,10 @@ func TestAuthorizationClient_New(t *testing.T) { "idempotency_key", "payment_id", &AuthorizationParams{ - PaymentMethodToken: "token", + PaymentMethod: PaymentMethodDetails{ + Type: "tokenized", + Token: "token", + }, }, &ClientInfo{ IPAddress: "ip", diff --git a/capture.go b/capture.go index b3b1f2e..8860889 100644 --- a/capture.go +++ b/capture.go @@ -24,8 +24,8 @@ type Capture struct { // CaptureParams is a set of params for creating entity. type CaptureParams struct { - ReconciliationID string `json:"reconciliation_id,omitempty"` - Amount float64 `json:"amount,omitempty"` + ReconciliationID string `json:"reconciliation_id,omitempty"` + Amount int64 `json:"amount,omitempty"` } // New creates new Capture entity. diff --git a/charge.go b/charge.go index 0217ea3..63ed431 100644 --- a/charge.go +++ b/charge.go @@ -16,10 +16,10 @@ type ChargeClient struct { type Charge struct { ID string `json:"id"` Result Result `json:"result"` - Amount float64 `json:"amount"` + Amount int64 `json:"amount"` Created json.Number `json:"created"` ReconciliationID string `json:"reconciliation_id"` - PaymentMethod PaymentMethod `json:"payment_method"` + PaymentMethod PaymentMethodHref `json:"payment_method"` ThreeDSecureAttributes *ThreeDSecureAttributes `json:"three_d_secure_attributes"` Installments *Installments `json:"installments"` ProviderData ProviderData `json:"provider_data"` @@ -31,8 +31,7 @@ type Charge struct { // ChargeParams is a set of params for creating entity. type ChargeParams struct { - PaymentMethodToken string `json:"payment_method_token"` - CreditCardCvv string `json:"credit_card_cvv,omitempty"` + PaymentMethod PaymentMethodDetails `json:"payment_method"` MerchantSiteURL string `json:"merchant_site_url,omitempty"` ReconciliationID string `json:"reconciliation_id,omitempty"` ThreeDSecureAttributes *ThreeDSecureAttributes `json:"three_d_secure_attributes,omitempty"` diff --git a/charge_test.go b/charge_test.go index c2a353f..90977d2 100644 --- a/charge_test.go +++ b/charge_test.go @@ -16,7 +16,10 @@ func TestChargeClient_New(t *testing.T) { headerClientUserAgent: "ua", }, expectedReqObj: &ChargeParams{ - PaymentMethodToken: "token", + PaymentMethod: PaymentMethodDetails{ + Type: "tokenized", + Token: "token", + }, }, returnRespObj: &Charge{ ID: "id", @@ -30,7 +33,10 @@ func TestChargeClient_New(t *testing.T) { "idempotency_key", "payment_id", &ChargeParams{ - PaymentMethodToken: "token", + PaymentMethod: PaymentMethodDetails{ + Type: "tokenized", + Token: "token", + }, }, &ClientInfo{ IPAddress: "ip", diff --git a/client.go b/client.go index ce0feaf..1c33cb5 100644 --- a/client.go +++ b/client.go @@ -42,7 +42,7 @@ type Client struct { type env string const ( - apiVersion = "1.0.0" + apiVersion = "1.2.0" apiURL = "https://api.paymentsos.com/" // EnvTest is a value for test environment header diff --git a/common.go b/common.go index 61af2bb..a76a56c 100644 --- a/common.go +++ b/common.go @@ -26,6 +26,7 @@ type Address struct { FirstName string `json:"first_name,omitempty"` LastName string `json:"last_name,omitempty"` Phone string `json:"phone,omitempty"` + Email string `json:"email,omitempty"` } // AdditionalDetails is a set of any custom key-value info. @@ -41,9 +42,9 @@ type ThreeDSecureAttributes struct { // Installments is a set of options of installments. type Installments struct { - NumberOfInstallments int `json:"number_of_installments"` - FirstPaymentAmount float64 `json:"first_payment_amount"` - RemainingPaymentsAmount float64 `json:"remaining_payments_amount"` + NumberOfInstallments int64 `json:"number_of_installments"` + FirstPaymentAmount int64 `json:"first_payment_amount"` + RemainingPaymentsAmount int64 `json:"remaining_payments_amount"` } // ProviderData is a set of params describing payment provider. @@ -66,3 +67,19 @@ type ProviderDocument struct { ContentType string `json:"content_type"` Href string `json:"href"` } + +// PaymentMethodDetails represents payment method details for POST requests. +type PaymentMethodDetails struct { + Type string `json:"type"` + Token string `json:"token,omitempty"` + CreditCardCvv string `json:"credit_card_cvv,omitempty"` + SourceType string `json:"source_type,omitempty"` + Vendor string `json:"vendor,omitempty"` + AdditionalDetails AdditionalDetails `json:"additional_details,omitempty"` +} + +// PaymentMethodHref wraps PaymentMethod with associated href. +type PaymentMethodHref struct { + Href string `json:"href"` + PaymentMethod *PaymentMethod `json:"payment_method"` +} diff --git a/payment.go b/payment.go index 88bde59..619b761 100644 --- a/payment.go +++ b/payment.go @@ -24,14 +24,14 @@ type Payment struct { PossibleNextActions []PaymentNextAction `json:"possible_next_actions"` // Expansions - PaymentMethod *PaymentMethod `json:"payment_method"` + PaymentMethod *PaymentMethodHref `json:"payment_method"` Customer *Customer `json:"customer"` RelatedResources *PaymentRelatedResources `json:"related_resources"` } // PaymentParams is a set of params for creating and updating entity. type PaymentParams struct { - Amount float64 `json:"amount"` + Amount int64 `json:"amount"` Currency string `json:"currency"` CustomerID string `json:"customer_id,omitempty"` AdditionalDetails AdditionalDetails `json:"additional_details,omitempty"` @@ -45,17 +45,17 @@ type PaymentParams struct { type PaymentOrder struct { ID string `json:"id,omitempty"` AdditionalDetails AdditionalDetails `json:"additional_details,omitempty"` - TaxAmount float64 `json:"tax_amount,omitempty"` - TaxPercentage float64 `json:"tax_percentage,omitempty"` + TaxAmount int64 `json:"tax_amount,omitempty"` + TaxPercentage int64 `json:"tax_percentage,omitempty"` LineItems []PaymentOrderLineItem `json:"line_items,omitempty"` } // PaymentOrderLineItem represents one item of order. type PaymentOrderLineItem struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Quantity int `json:"quantity,omitempty"` - UnitPrice float64 `json:"unit_price,omitempty"` + ID string `json:"id,omitempty"` + Name string `json:"name,omitempty"` + Quantity int64 `json:"quantity,omitempty"` + UnitPrice int64 `json:"unit_price,omitempty"` } // PaymentNextAction represents action which may be performed on Payment entity. diff --git a/payment_method.go b/payment_method.go index b804ef8..c9390b3 100644 --- a/payment_method.go +++ b/payment_method.go @@ -15,6 +15,7 @@ type PaymentMethodClient struct { // PaymentMethod is a entity model. type PaymentMethod struct { Type string `json:"type"` + TokenType string `json:"token_type"` PassLuhnValidation bool `json:"pass_luhn_validation"` Token string `json:"token"` Created json.Number `json:"created"` diff --git a/refund.go b/refund.go index 12379a8..9247b63 100644 --- a/refund.go +++ b/refund.go @@ -24,10 +24,10 @@ type Refund struct { // RefundParams is a set of params for creating entity. type RefundParams struct { - ReconciliationID string `json:"reconciliation_id,omitempty"` - Amount float64 `json:"amount,omitempty"` - CaptureID string `json:"capture_id,omitempty"` - Reason string `json:"reason,omitempty"` + ReconciliationID string `json:"reconciliation_id,omitempty"` + Amount int64 `json:"amount,omitempty"` + CaptureID string `json:"capture_id,omitempty"` + Reason string `json:"reason,omitempty"` } // New creates new Refund entity.