Skip to content

Commit

Permalink
Merge pull request #9 from brainly/api_update
Browse files Browse the repository at this point in the history
Update to API version 1.2
  • Loading branch information
vpbarb authored Jun 5, 2018
2 parents add73fe + 7214eb2 commit 9b1604f
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 30 deletions.
7 changes: 3 additions & 4 deletions authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
Expand Down
10 changes: 8 additions & 2 deletions authorization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 3 additions & 4 deletions charge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
Expand Down
10 changes: 8 additions & 2 deletions charge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 20 additions & 3 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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"`
}
16 changes: 8 additions & 8 deletions payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions payment_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
8 changes: 4 additions & 4 deletions refund.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 9b1604f

Please sign in to comment.