Skip to content

Commit

Permalink
Update Payment Context And Properties (#101)
Browse files Browse the repository at this point in the history
- Update payment request for payment contexts
- Update giropay source
- Update properties and tests
  • Loading branch information
armando-rodriguez-cko authored Feb 8, 2024
1 parent 7d0728a commit 51cb07b
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 50 deletions.
100 changes: 52 additions & 48 deletions payments/nas/payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,33 +82,36 @@ type (
// Request
type (
PaymentRequest struct {
Source payments.PaymentSource `json:"source,omitempty"`
Amount int64 `json:"amount,omitempty"`
Currency common.Currency `json:"currency,omitempty"`
PaymentType payments.PaymentType `json:"payment_type,omitempty"`
MerchantInitiated bool `json:"merchant_initiated"`
Reference string `json:"reference,omitempty"`
Description string `json:"description,omitempty"`
AuthorizationType AuthorizationType `json:"authorization_type,omitempty"`
Capture bool `json:"capture"`
CaptureOn *time.Time `json:"capture_on,omitempty"`
Customer *common.CustomerRequest `json:"customer,omitempty"`
BillingDescriptor *payments.BillingDescriptor `json:"billing_descriptor,omitempty"`
ShippingDetails *payments.ShippingDetails `json:"shipping,omitempty"`
ThreeDsRequest *payments.ThreeDsRequest `json:"3ds,omitempty"`
PreviousPaymentId string `json:"previous_payment_id,omitempty"`
ProcessingChannelId string `json:"processing_channel_id,omitempty"`
Risk *payments.RiskRequest `json:"risk,omitempty"`
SuccessUrl string `json:"success_url,omitempty"`
FailureUrl string `json:"failure_url,omitempty"`
PaymentIp string `json:"payment_ip,omitempty"`
Sender Sender `json:"sender,omitempty"`
Recipient *payments.PaymentRecipient `json:"recipient,omitempty"`
Marketplace *common.MarketplaceData `json:"marketplace,omitempty"`
AmountAllocations []common.AmountAllocations `json:"amount_allocations,omitempty"`
Processing *payments.ProcessingSettings `json:"processing,omitempty"`
Items []payments.Product `json:"items,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
PaymentContextId string `json:"payment_context_id,omitempty"`
Source payments.PaymentSource `json:"source,omitempty"`
Amount int64 `json:"amount,omitempty"`
Currency common.Currency `json:"currency,omitempty"`
PaymentType payments.PaymentType `json:"payment_type,omitempty"`
MerchantInitiated bool `json:"merchant_initiated"`
Reference string `json:"reference,omitempty"`
Description string `json:"description,omitempty"`
AuthorizationType AuthorizationType `json:"authorization_type,omitempty"`
Capture bool `json:"capture"`
CaptureOn *time.Time `json:"capture_on,omitempty"`
Customer *common.CustomerRequest `json:"customer,omitempty"`
BillingDescriptor *payments.BillingDescriptor `json:"billing_descriptor,omitempty"`
ShippingDetails *payments.ShippingDetails `json:"shipping,omitempty"`
Segment *payments.PaymentSegment `json:"segment,omitempty"`
ThreeDsRequest *payments.ThreeDsRequest `json:"3ds,omitempty"`
PreviousPaymentId string `json:"previous_payment_id,omitempty"`
ProcessingChannelId string `json:"processing_channel_id,omitempty"`
Risk *payments.RiskRequest `json:"risk,omitempty"`
SuccessUrl string `json:"success_url,omitempty"`
FailureUrl string `json:"failure_url,omitempty"`
PaymentIp string `json:"payment_ip,omitempty"`
Sender Sender `json:"sender,omitempty"`
Recipient *payments.PaymentRecipient `json:"recipient,omitempty"`
Marketplace *common.MarketplaceData `json:"marketplace,omitempty"`
AmountAllocations []common.AmountAllocations `json:"amount_allocations,omitempty"`
Processing *payments.ProcessingSettings `json:"processing,omitempty"`
Items []payments.Product `json:"items,omitempty"`
Retry *payments.PaymentRetryRequest `json:"retry,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}

PayoutRequest struct {
Expand Down Expand Up @@ -150,27 +153,28 @@ type (
type (
PaymentResponse struct {
HttpMetadata common.HttpMetadata
ActionId string `json:"action_id,omitempty"`
Amount int64 `json:"amount,omitempty"`
Approved bool `json:"approved,omitempty"`
AuthCode string `json:"auth_code,omitempty"`
Id string `json:"id,omitempty"`
Currency common.Currency `json:"currency,omitempty"`
Customer *common.CustomerResponse `json:"customer,omitempty"`
Source *SourceResponse `json:"source,omitempty"`
Status payments.PaymentStatus `json:"status,omitempty"`
ThreeDs *payments.ThreeDsEnrollment `json:"3ds,omitempty"`
Reference string `json:"reference,omitempty"`
ResponseCode string `json:"response_code,omitempty"`
ResponseSummary string `json:"response_summary,omitempty"`
Risk *payments.RiskAssessment `json:"risk,omitempty"`
ProcessedOn *time.Time `json:"processed_on,omitempty"`
ExpiresOn *time.Time `json:"expires_on,omitempty"`
Balances *PaymentResponseBalances `json:"balances,omitempty"`
Processing *payments.PaymentProcessing `json:"processing,omitempty"`
Eci string `json:"eci,omitempty"`
SchemeId string `json:"scheme_id,omitempty"`
Links map[string]common.Link `json:"_links"`
ActionId string `json:"action_id,omitempty"`
Amount int64 `json:"amount,omitempty"`
Approved bool `json:"approved,omitempty"`
AuthCode string `json:"auth_code,omitempty"`
Id string `json:"id,omitempty"`
Currency common.Currency `json:"currency,omitempty"`
Customer *common.CustomerResponse `json:"customer,omitempty"`
Source *SourceResponse `json:"source,omitempty"`
Status payments.PaymentStatus `json:"status,omitempty"`
ThreeDs *payments.ThreeDsEnrollment `json:"3ds,omitempty"`
Reference string `json:"reference,omitempty"`
ResponseCode string `json:"response_code,omitempty"`
ResponseSummary string `json:"response_summary,omitempty"`
Risk *payments.RiskAssessment `json:"risk,omitempty"`
ProcessedOn *time.Time `json:"processed_on,omitempty"`
ExpiresOn *time.Time `json:"expires_on,omitempty"`
Balances *PaymentResponseBalances `json:"balances,omitempty"`
Processing *payments.PaymentProcessing `json:"processing,omitempty"`
Eci string `json:"eci,omitempty"`
SchemeId string `json:"scheme_id,omitempty"`
Retry *payments.PaymentRetryResponse `json:"retry,omitempty"`
Links map[string]common.Link `json:"_links"`
}

PayoutResponse struct {
Expand Down
1 change: 1 addition & 0 deletions payments/nas/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type (
AvsCheck string `json:"avs_check,omitempty"`
CvvCheck string `json:"cvv_check,omitempty"`
PaymentAccountReference string `json:"payment_account_reference,omitempty"`
EncryptedCardNumber string `json:"encrypted_card_number,omitempty"`
}

ResponseCurrencyAccountSource struct {
Expand Down
3 changes: 2 additions & 1 deletion payments/nas/sources/apm/apm.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ type (
}

requestGiropaySource struct {
Type payments.SourceType `json:"type,omitempty"`
Type payments.SourceType `json:"type,omitempty"`
AccountHolder *common.AccountHolder `json:"account_holder,omitempty"`
}

requestIdealSource struct {
Expand Down
21 changes: 21 additions & 0 deletions payments/payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,18 @@ type (
Delay int `json:"delay,omitempty"`
}

PaymentSegment struct {
Brand string `json:"brand,omitempty"`
BusinessCategory string `json:"business_category,omitempty"`
Market string `json:"market,omitempty"`
}

PaymentRetryRequest struct {
Enabled bool `json:"enabled,omitempty"`
MaxAttempts int `json:"max_attempts,omitempty"`
EndAfterDays int `json:"end_after_days,omitempty"`
}

BillingDescriptor struct {
Name string `json:"name,omitempty"`
City string `json:"city,omitempty"`
Expand Down Expand Up @@ -319,6 +331,9 @@ type (
RetrievalReferenceNumber string `json:"retrieval_reference_number,omitempty"`
AcquirerTransactionId string `json:"acquirer_transaction_id,omitempty"`
RecommendationCode string `json:"recommendation_code,omitempty"`
Scheme string `json:"scheme,omitempty"`
PartnerMerchantAdviceCode string `json:"partner_merchant_advice_code,omitempty"`
PartnerResponseCode string `json:"partner_response_code,omitempty"`
PartnerOrderId string `json:"partner_order_id,omitempty"`
PartnerSessionId string `json:"partner_session_id,omitempty"`
PartnerClientToken string `json:"partner_client_token,omitempty"`
Expand All @@ -333,6 +348,12 @@ type (
PartnerAuthorizationResponseCode string `json:"partner_authorization_response_code,omitempty"`
}

PaymentRetryResponse struct {
MaxAttempts int `json:"max_attempts,omitempty"`
EndsOn *time.Time `json:"ends_on,omitempty"`
NextAttemptOn *time.Time `json:"next_attempt_on,omitempty"`
}

ThreeDsData struct {
Downgraded bool `json:"downgraded,omitempty"`
Enrolled string `json:"enrolled,omitempty"`
Expand Down
8 changes: 7 additions & 1 deletion test/payments_request_apm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func TestRequestPaymentsAPM(t *testing.T) {
assert.Nil(t, response)
ckoErr := err.(errors.CheckoutAPIError)
assert.Equal(t, http.StatusUnprocessableEntity, ckoErr.StatusCode)
assert.Equal(t, "payment_type_required", ckoErr.Data.ErrorCodes[0])
assert.Equal(t, "apm_service_unavailable", ckoErr.Data.ErrorCodes[0])
},
},
}
Expand Down Expand Up @@ -538,7 +538,13 @@ func getEpsSource() payments.PaymentSource {
}

func getGiropaySource() payments.PaymentSource {
accountHolder := common.AccountHolder{
FirstName: FirstName,
LastName: LastName,
}

source := apm.NewRequestGiropaySource()
source.AccountHolder = &accountHolder

return source
}
Expand Down

0 comments on commit 51cb07b

Please sign in to comment.