From 86227db712deafcf5a731452efec386fb1749394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20Rodr=C3=ADguez?= <127134616+armando-rodriguez-cko@users.noreply.github.com> Date: Wed, 14 Aug 2024 17:05:01 +0200 Subject: [PATCH] Update payment sessions schemas (#122) --- common/common.go | 65 ++++++++++--- sessions/channels/channels.go | 46 +++++++-- sessions/sessions.go | 77 +++++++++++---- sessions/sessions_requests.go | 108 ++++++++++++++------- sessions/sessions_responses.go | 140 ++++++++++++++++++---------- sessions/sources/session_sources.go | 10 +- test/reports_test.go | 18 +++- test/sessions_test.go | 72 ++++++++++++-- workflows/client_test.go | 2 +- 9 files changed, 397 insertions(+), 141 deletions(-) diff --git a/common/common.go b/common/common.go index 4c6cf5a..f03780c 100644 --- a/common/common.go +++ b/common/common.go @@ -23,19 +23,20 @@ const ( type CardType string const ( + Charge CardType = "Charge" Credit CardType = "Credit" Debit CardType = "Debit" - Prepaid CardType = "Prepaid" - Charge CardType = "Charge" DeferredDebit CardType = "Deferred Debit" + Prepaid CardType = "Prepaid" ) type CardCategory string const ( - Consumer CardCategory = "Consumer" - Commercial CardCategory = "Commercial" All CardCategory = "All" + Commercial CardCategory = "Commercial" + Consumer CardCategory = "Consumer" + NotSet CardCategory = "NotSet" OtherCardCategory CardCategory = "Other" ) @@ -50,10 +51,15 @@ const ( type ChallengeIndicator string const ( - NoPreference ChallengeIndicator = "no_preference" - NoChallengeRequested ChallengeIndicator = "no_challenge_requested" - ChallengeRequested ChallengeIndicator = "challenge_requested" - ChallengeRequestedMandate ChallengeIndicator = "challenge_requested_mandate" + ChallengeRequested ChallengeIndicator = "challenge_requested" + ChallengeRequestedMandate ChallengeIndicator = "challenge_requested_mandate" + ChallengeIndicatorDataShare ChallengeIndicator = "data_share" + ChallengeIndicatorLowValue ChallengeIndicator = "low_value" + NoChallengeRequested ChallengeIndicator = "no_challenge_requested" + NoPreference ChallengeIndicator = "no_preference" + ChallengeIndicatorTransactionRiskAssessment ChallengeIndicator = "transaction_risk_assessment" + ChallengeIndicatorTrustedListing ChallengeIndicator = "trusted_listing" + ChallengeIndicatorTrustedListingPrompt ChallengeIndicator = "trusted_listing_prompt" ) type DocumentType string @@ -88,17 +94,17 @@ const ( type Exemption string const ( - None Exemption = "none" + LowRiskProgram Exemption = "low_risk_program" LowValue Exemption = "low_value" + None Exemption = "none" + Other Exemption = "other" + OutOfScaScope Exemption = "out_of_sca_scope" RecurringOperation Exemption = "recurring_operation" - TransactionRiskAssessment Exemption = "transaction_risk_assessment" + ScaDelegation Exemption = "sca_delegation" SecureCorporatePayment Exemption = "secure_corporate_payment" - TrustedListing Exemption = "trusted_listing" ThreeDsOutage Exemption = "3ds_outage" - ScaDelegation Exemption = "sca_delegation" - OutOfScaScope Exemption = "out_of_sca_scope" - Other Exemption = "other" - LowRiskProgram Exemption = "low_risk_program" + TransactionRiskAssessment Exemption = "transaction_risk_assessment" + TrustedListing Exemption = "trusted_listing" ) type ThreeDsMethodCompletion string @@ -290,3 +296,32 @@ type ( Bank *BankDetails `json:"bank,omitempty"` } ) + +type CardholderAccountAgeIndicatorType string + +const ( + CardholderLessThanThirtyDays CardholderAccountAgeIndicatorType = "less_than_thirty_days" + CardholderMoreThanSixtyDays CardholderAccountAgeIndicatorType = "more_than_sixty_days" + CardholderNoAccount CardholderAccountAgeIndicatorType = "no_account" + CardholderThirtyToSixtyDays CardholderAccountAgeIndicatorType = "thirty_to_sixty_days" + CardholderThisTransaction CardholderAccountAgeIndicatorType = "this_transaction" +) + +type AccountChangeIndicatorType string + +const ( + AccountChangeLessThanThirtyDays AccountChangeIndicatorType = "less_than_thirty_days" + AccountChangeMoreThanSixtyDays AccountChangeIndicatorType = "more_than_sixty_days" + AccountChangeThirtyToSixtyDays AccountChangeIndicatorType = "thirty_to_sixty_days" + AccountChangeThisTransaction AccountChangeIndicatorType = "this_transaction" +) + +type AccountPasswordChangeIndicatorType string + +const ( + PasswordChangeLessThanThirtyDays AccountPasswordChangeIndicatorType = "less_than_thirty_days" + PasswordChangeMoreThanSixtyDays AccountPasswordChangeIndicatorType = "more_than_sixty_days" + PasswordChangeNoChange AccountPasswordChangeIndicatorType = "no_change" + PasswordChangeThirtyToSixtyDays AccountPasswordChangeIndicatorType = "thirty_to_sixty_days" + PasswordChangeThisTransaction AccountPasswordChangeIndicatorType = "this_transaction" +) diff --git a/sessions/channels/channels.go b/sessions/channels/channels.go index d594095..c04f30a 100644 --- a/sessions/channels/channels.go +++ b/sessions/channels/channels.go @@ -7,26 +7,43 @@ import ( type ChannelType string const ( - Browser ChannelType = "browser" - App ChannelType = "app" + App ChannelType = "app" + Browser ChannelType = "browser" + MerchantInitiated ChannelType = "merchant_initiated" ) type SdkInterfaceType string const ( - Native SdkInterfaceType = "native" - Html SdkInterfaceType = "html" Both SdkInterfaceType = "both" + Html SdkInterfaceType = "html" + Native SdkInterfaceType = "native" ) type UIElements string const ( - Text UIElements = "text" - SingleSelect UIElements = "single_select" + HtmlOther UIElements = "html_other" MultiSelect UIElements = "multi_select" Oob UIElements = "oob" - HtmlOther UIElements = "html_other" + SingleSelect UIElements = "single_select" + Text UIElements = "text" +) + +type RequestType string + +const ( + AccountVerification RequestType = "account_verification" + AddCard RequestType = "add_card" + InstallmentTransaction RequestType = "installment_transaction" + MailOrder RequestType = "mail_order" + MaintainCardInformation RequestType = "maintain_card_information" + OtherPayment RequestType = "other_payment" + RecurringTransaction RequestType = "recurring_transaction" + SplitOrDelayedShipment RequestType = "split_or_delayed_shipment" + TelephoneOrder RequestType = "telephone_order" + TopUp RequestType = "top_up" + WhitelistStatusCheck RequestType = "whitelist_status_check" ) type ( @@ -52,7 +69,7 @@ type ( browserSession struct { ChannelData - ThreeDsMethodCompletion common.ThreeDsMethodCompletion `json:"three_ds_method_completion,omitempty"` + ThreeDsMethodCompletion common.ThreeDsMethodCompletion `json:"three_ds_method_completion,omitempty" default:"u"` AcceptHeader string `json:"accept_header,omitempty"` JavaEnabled bool `json:"java_enabled,omitempty"` JavascriptEnabled bool `json:"javascript_enabled,omitempty"` @@ -64,6 +81,11 @@ type ( UserAgent string `json:"user_agent,omitempty"` IpAddress string `json:"ip_address,omitempty"` } + + merchantInitiatedSession struct { + ChannelData + RequestType RequestType `json:"request_type,omitempty"` + } ) func NewAppSession() *appSession { @@ -74,6 +96,10 @@ func NewBrowserSession() *browserSession { return &browserSession{ChannelData: ChannelData{Channel: Browser}} } +func NewMerchantInitiatedSession() *merchantInitiatedSession { + return &merchantInitiatedSession{ChannelData: ChannelData{Channel: MerchantInitiated}} +} + func (s *appSession) GetType() ChannelType { return s.Channel } @@ -82,6 +108,10 @@ func (s *browserSession) GetType() ChannelType { return s.Channel } +func (s *merchantInitiatedSession) GetType() ChannelType { + return s.Channel +} + type SdkEphemeralPublicKey struct { Kty string `json:"kty,omitempty"` Crv string `json:"crv,omitempty"` diff --git a/sessions/sessions.go b/sessions/sessions.go index 9b329bd..80e4100 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -1,5 +1,7 @@ package sessions +import "time" + const ( SessionsPath = "sessions" CollectDataPath = "collect-data" @@ -10,11 +12,11 @@ const ( type AuthenticationType string const ( - RegularAuthType AuthenticationType = "regular" - RecurringAuthType AuthenticationType = "recurring" + AddCardAuthType AuthenticationType = "add_card" InstallmentAuthType AuthenticationType = "installment" MaintainCardAuthType AuthenticationType = "maintain_card" - AddCardAuthType AuthenticationType = "add_card" + RecurringAuthType AuthenticationType = "recurring" + RegularAuthType AuthenticationType = "regular" ) type Category string @@ -27,26 +29,26 @@ const ( type TransactionType string const ( - GoodsService TransactionType = "goods_service" - CheckAcceptance TransactionType = "check_acceptance" AccountFunding TransactionType = "account_funding" - QuashiCardTransaction TransactionType = "quashi_card_transaction" + CheckAcceptance TransactionType = "check_acceptance" + GoodsService TransactionType = "goods_service" PrepaidActivationAndLoad TransactionType = "prepaid_activation_and_load" + QuashiCardTransaction TransactionType = "quashi_card_transaction" ) type SessionStatus string const ( - Pending SessionStatus = "pending" - Processing SessionStatus = "processing" - Challenged SessionStatus = "challenged" - ChallengeAbandoned SessionStatus = "challenge_abandoned" - Expired SessionStatus = "expired" Approved SessionStatus = "approved" Attempted SessionStatus = "attempted" - Unavailable SessionStatus = "unavailable" + Challenged SessionStatus = "challenged" + ChallengeAbandoned SessionStatus = "challenge_abandoned" Declined SessionStatus = "declined" + Expired SessionStatus = "expired" + Pending SessionStatus = "pending" + Processing SessionStatus = "processing" Rejected SessionStatus = "rejected" + Unavailable SessionStatus = "unavailable" ) type StatusReason string @@ -66,21 +68,58 @@ const ( type NextAction string const ( + Authenticate NextAction = "authenticate" + ChallengeCardHolder NextAction = "challenge_cardholder" CollectChannelData NextAction = "collect_channel_data" + Complete NextAction = "complete" IssueFingerprint NextAction = "issuer_fingerprint" - ChallengeCardHolder NextAction = "challenge_cardholder" RedirectCardholder NextAction = "redirect_cardholder" - Complete NextAction = "complete" - Authenticate NextAction = "authenticate" +) + +type DeliveryTimeframe string + +const ( + ElectronicDelivery DeliveryTimeframe = "electronic_delivery" + SameDay DeliveryTimeframe = "same_day" + Overnight DeliveryTimeframe = "overnight" + TwoDayOrMore DeliveryTimeframe = "two_day_or_more" +) + +type PreOrderPurchaseIndicatorType string + +const ( + FutureAvailability PreOrderPurchaseIndicatorType = "future_availability" + MerchandiseAvailable PreOrderPurchaseIndicatorType = "merchandise_available" +) + +type ReorderItemsIndicatorType string + +const ( + FirstTimeOrdered ReorderItemsIndicatorType = "first_time_ordered" + Reordered ReorderItemsIndicatorType = "reordered" ) type Recurring struct { - DaysBetweenPayments int `json:"days_between_payments,omitempty"` - Expiry string `json:"expiry,omitempty"` + DaysBetweenPayments int `json:"days_between_payments,omitempty" default:"1"` + Expiry string `json:"expiry,omitempty" default:"99991231"` } type Installment struct { NumberOfPayments int `json:"number_of_payments,omitempty"` - DaysBetweenPayments int `json:"days_between_payments,omitempty"` - Expiry string `json:"expiry,omitempty"` + DaysBetweenPayments int `json:"days_between_payments,omitempty" default:"1"` + Expiry string `json:"expiry,omitempty" default:"99991231"` +} + +type MerchantRiskInfo struct { + DeliveryEmail string `json:"delivery_email,omitempty"` + DeliveryTimeframe DeliveryTimeframe `json:"delivery_timeframe,omitempty"` + IsPreorder bool `json:"is_preorder,omitempty"` + IsReorder bool `json:"is_reorder,omitempty"` + ShippingIndicator ShippingIndicator `json:"shipping_indicator,omitempty"` + ReorderItemsIndicator ReorderItemsIndicatorType `json:"reorder_items_indicator,omitempty"` + PreOrderPurchaseIndicator PreOrderPurchaseIndicatorType `json:"pre_order_purchase_indicator,omitempty"` + PreOrderDate *time.Time `json:"pre_order_date,omitempty"` + GiftCardAmount string `json:"gift_card_amount,omitempty"` + GiftCardCurrency string `json:"gift_card_currency,omitempty"` + GiftCardCount string `json:"gift_card_count,omitempty"` } diff --git a/sessions/sessions_requests.go b/sessions/sessions_requests.go index ffd3c83..a30f45f 100644 --- a/sessions/sessions_requests.go +++ b/sessions/sessions_requests.go @@ -1,6 +1,8 @@ package sessions import ( + "time" + "github.com/checkout/checkout-sdk-go/common" "github.com/checkout/checkout-sdk-go/sessions/channels" "github.com/checkout/checkout-sdk-go/sessions/completion" @@ -10,27 +12,78 @@ import ( type AuthenticationMethod string const ( - NoAuthentication AuthenticationMethod = "no_authentication" - OwnCredentials AuthenticationMethod = "own_credentials" FederatedId AuthenticationMethod = "federated_id" + Fido AuthenticationMethod = "fido" IssuerCredentials AuthenticationMethod = "issuer_credentials" + NoAuthentication AuthenticationMethod = "no_authentication" + OwnCredentials AuthenticationMethod = "own_credentials" ThirdPartyAuthentication AuthenticationMethod = "third_party_authentication" - Fido AuthenticationMethod = "fido" ) -type DeliveryTimeframe string +type ShippingIndicator string + +const ( + Visa ShippingIndicator = "visa" +) + +type AccountTypeCardProductType string const ( - ElectronicDelivery DeliveryTimeframe = "electronic_delivery" - SameDay DeliveryTimeframe = "same_day" - Overnight DeliveryTimeframe = "overnight" - TwoDayOrMore DeliveryTimeframe = "two_day_or_more" + Credit AccountTypeCardProductType = "credit" + Debit AccountTypeCardProductType = "debit" + NotApplicable AccountTypeCardProductType = "not_applicable" ) -type ShippingIndicator string +type ThreeDsReqAuthMethodType string const ( - Visa ShippingIndicator = "visa" + ThreeDsFederatedId ThreeDsReqAuthMethodType = "federated_id" + ThreeDsFidoAuthenticator ThreeDsReqAuthMethodType = "fido_authenticator" + ThreeDsFidoAuthenticatorFidoAssuranceDataSigned ThreeDsReqAuthMethodType = "fido_authenticator_fido_assurance_data_signed" + ThreeDsIssuerCredentials ThreeDsReqAuthMethodType = "issuer_credentials" + ThreeDsNoAuthenticationOccurred ThreeDsReqAuthMethodType = "no_threeds_requestor_authentication_occurred" + ThreeDsSrcAssuranceData ThreeDsReqAuthMethodType = "src_assurance_data" + ThreeDsOwnCredentials ThreeDsReqAuthMethodType = "three3ds_requestor_own_credentials" + ThreeDsThirdPartyAuthentication ThreeDsReqAuthMethodType = "third_party_authentication" +) + +type ( + ThreeDsRequestorAuthenticationInfo struct { + ThreeDsReqAuthMethod *ThreeDsReqAuthMethodType `json:"three_ds_req_auth_method,omitempty"` + ThreeDsReqAuthTimestamp *time.Time `json:"three_ds_req_auth_timestamp,omitempty"` + ThreeDsReqAuthData string `json:"three_ds_req_auth_data,omitempty"` + } + + CardholderAccountInfo struct { + PurchaseCount int64 `json:"purchase_count,omitempty"` + AccountAge string `json:"account_age,omitempty"` + AddCardAttempts int64 `json:"add_card_attempts,omitempty"` + ShippingAddressAge string `json:"shipping_address_age,omitempty"` + AccountNameMatchesShippingName bool `json:"account_name_matches_shipping_name,omitempty"` + SuspiciousAccountActivity bool `json:"suspicious_account_activity,omitempty"` + TransactionsToday int64 `json:"transactions_today,omitempty"` + AuthenticationMethod *AuthenticationMethod `json:"authentication_method,omitempty"` // Deprecated field + CardholderAccountAgeIndicator common.CardholderAccountAgeIndicatorType `json:"cardholder_account_age_indicator,omitempty"` + AccountChange *time.Time `json:"account_change,omitempty"` + AccountChangeIndicator common.AccountChangeIndicatorType `json:"account_change_indicator,omitempty"` + AccountDate *time.Time `json:"account_date,omitempty"` + AccountPasswordChange string `json:"account_password_change,omitempty"` + AccountPasswordChangeIndicator common.AccountPasswordChangeIndicatorType `json:"account_password_change_indicator,omitempty"` + TransactionsPerYear int `json:"transactions_per_year,omitempty"` + PaymentAccountAge *time.Time `json:"payment_account_age,omitempty"` + ShippingAddressUsage *time.Time `json:"shipping_address_usage,omitempty"` + AccountType AccountTypeCardProductType `json:"account_type,omitempty"` + AccountId string `json:"account_id,omitempty"` + ThreeDsRequestorAuthenticationInfo *ThreeDsRequestorAuthenticationInfo `json:"three_ds_requestor_authentication_info,omitempty"` + } + + SessionMarketplaceData struct { + SubEntityId string `json:"sub_entity_id,omitempty"` + } + + SessionsBillingDescriptor struct { + Name string `json:"name,omitempty"` + } ) type ( @@ -55,6 +108,8 @@ type ( ChannelData channels.Channel `json:"channel_data,omitempty"` Recurring *Recurring `json:"recurring,omitempty"` Installment *Installment `json:"installment,omitempty"` + Optimization *Optimization `json:"optimization,omitempty"` + InitialTransaction *InitialTransaction `json:"initial_transaction,omitempty"` } ThreeDsMethodCompletionRequest struct { @@ -62,29 +117,12 @@ type ( } ) -type SessionMarketplaceData struct { - SubEntityId string `json:"sub_entity_id,omitempty"` -} - -type CardholderAccountInfo struct { - PurchaseCount int `json:"purchase_count,omitempty"` - AccountAge string `json:"account_age,omitempty"` - AddCardAttempts int `json:"add_card_attempts,omitempty"` - ShippingAddressAge string `json:"shipping_address_age,omitempty"` - AccountNameMatchesShippingName bool `json:"account_name_matches_shipping_name,omitempty"` - SuspiciousAccountActivity bool `json:"suspicious_account_activity,omitempty"` - TransactionsToday int `json:"transactions_today,omitempty"` - AuthenticationMethod AuthenticationMethod `json:"authentication_method,omitempty"` -} - -type SessionsBillingDescriptor struct { - Name string `json:"name,omitempty"` -} - -type MerchantRiskInfo struct { - DeliveryEmail string `json:"delivery_email,omitempty"` - DeliveryTimeframe DeliveryTimeframe `json:"delivery_timeframe,omitempty"` - IsPreorder bool `json:"is_preorder,omitempty"` - IsReorder bool `json:"is_reorder,omitempty"` - ShippingIndicator ShippingIndicator `json:"shipping_indicator,omitempty"` +func NewSessionRequest() *SessionRequest { + return &SessionRequest{ + Source: sources.NewSessionCardSource(), + AuthenticationType: RegularAuthType, + AuthenticationCategory: Payment, + ChallengeIndicator: common.NoPreference, + TransactionType: GoodsService, + } } diff --git a/sessions/sessions_responses.go b/sessions/sessions_responses.go index b9215d1..0dc9794 100644 --- a/sessions/sessions_responses.go +++ b/sessions/sessions_responses.go @@ -22,21 +22,32 @@ const ( type SessionInterface string const ( - NativeUi SessionInterface = "native_ui" Html SessionInterface = "html" + NativeUi SessionInterface = "native_ui" ) type ResponseCode string const ( - Y ResponseCode = "Y" - N ResponseCode = "N" - U ResponseCode = "U" A ResponseCode = "A" C ResponseCode = "C" D ResponseCode = "D" - R ResponseCode = "R" I ResponseCode = "I" + N ResponseCode = "N" + R ResponseCode = "R" + U ResponseCode = "U" + Y ResponseCode = "Y" +) + +type TrustedBeneficiaryStatusType string + +const ( + TrustedBeneficiaryE TrustedBeneficiaryStatusType = "E" + TrustedBeneficiaryN TrustedBeneficiaryStatusType = "N" + TrustedBeneficiaryP TrustedBeneficiaryStatusType = "P" + TrustedBeneficiaryR TrustedBeneficiaryStatusType = "R" + TrustedBeneficiaryU TrustedBeneficiaryStatusType = "U" + TrustedBeneficiaryY TrustedBeneficiaryStatusType = "Y" ) type ( @@ -45,45 +56,69 @@ type ( Created *SessionDetails `json:"created,omitempty"` } + OptimizedProperty struct { + Field string `json:"field,omitempty"` + OriginalValue string `json:"original_value,omitempty"` + OptimizedValue string `json:"optimized_value,omitempty"` + } + + Optimization struct { + Optimized bool `json:"optimized,omitempty"` + Framework string `json:"framework,omitempty"` + OptimizedProperties []OptimizedProperty `json:"optimized_properties,omitempty"` + } + + InitialTransaction struct { + AcsTransactionId string `json:"acs_transaction_id,omitempty"` + AuthenticationMethod string `json:"authentication_method,omitempty"` + AuthenticationTimestamp string `json:"authentication_timestamp,omitempty"` + AuthenticationData string `json:"authentication_data,omitempty"` + InitialSessionId string `json:"initial_session_id,omitempty"` + } + SessionDetails struct { HttpMetadata common.HttpMetadata - Id string `json:"id,omitempty"` - SessionSecret string `json:"session_secret,omitempty"` - TransactionId string `json:"transaction_id,omitempty"` - Scheme sources.SessionScheme `json:"scheme,omitempty"` - Amount int64 `json:"amount,omitempty"` - Currency common.Currency `json:"currency,omitempty"` - Completed bool `json:"completed,omitempty"` - Challenged bool `json:"challenged,omitempty"` - AuthenticationType AuthenticationType `json:"authentication_type,omitempty"` - AuthenticationCategory Category `json:"authentication_category,omitempty"` - Certificates *DsPublicKeys `json:"certificates,omitempty"` - Status SessionStatus `json:"status,omitempty"` - StatusReason StatusReason `json:"status_reason,omitempty"` - Approved bool `json:"approved,omitempty"` - ProtocolVersion string `json:"protocol_version,omitempty"` - Reference string `json:"reference,omitempty"` - TransactionType TransactionType `json:"transaction_type,omitempty"` - NextActions []NextAction `json:"next_actions,omitempty"` - Ds *Ds `json:"ds,omitempty"` - Acs *Acs `json:"acs,omitempty"` - ResponseCode ResponseCode `json:"response_code,omitempty"` - ResponseStatusReason string `json:"response_status_reason,omitempty"` - Pareq string `json:"pareq,omitempty"` - Cryptogram string `json:"cryptogram,omitempty"` - Eci string `json:"eci,omitempty"` - Xid string `json:"xid,omitempty"` - CardholderInfo string `json:"cardholder_info,omitempty"` - Card *CardInfo `json:"card,omitempty"` - Recurring *Recurring `json:"recurring,omitempty"` - Installment *Installment `json:"installment,omitempty"` - CustomerIp string `json:"customer_ip,omitempty"` - AuthenticationDate *time.Time `json:"authentication_date,omitempty"` - Exemption *ThreeDsExemption `json:"exemption,omitempty"` - FlowType common.ThreeDsFlowType `json:"flow_type,omitempty"` - ChallengeIndicator common.ChallengeIndicator `json:"challenge_indicator,omitempty"` - SchemeInfo *SchemeInfo `json:"scheme_info,omitempty"` - Links map[string]common.Link `json:"_links"` + Id string `json:"id,omitempty"` + SessionSecret string `json:"session_secret,omitempty"` + TransactionId string `json:"transaction_id,omitempty"` + Scheme sources.SessionScheme `json:"scheme,omitempty"` + Amount int64 `json:"amount,omitempty"` + Currency common.Currency `json:"currency,omitempty"` + Completed bool `json:"completed,omitempty"` + Challenged bool `json:"challenged,omitempty"` + AuthenticationType AuthenticationType `json:"authentication_type,omitempty"` + AuthenticationCategory Category `json:"authentication_category,omitempty"` + Status SessionStatus `json:"status,omitempty"` + StatusReason StatusReason `json:"status_reason,omitempty"` + NextActions []NextAction `json:"next_actions,omitempty"` + ProtocolVersion string `json:"protocol_version,omitempty"` + AccountInfo *CardholderAccountInfo `json:"account_info,omitempty"` + MerchantRiskInfo *MerchantRiskInfo `json:"merchant_risk_info,omitempty"` + Reference string `json:"reference,omitempty"` + Card *CardInfo `json:"card,omitempty"` + Recurring *Recurring `json:"recurring,omitempty"` + Installment *Installment `json:"installment,omitempty"` + InitialTransaction *InitialTransaction `json:"initial_transaction,omitempty"` + AuthenticationDate *time.Time `json:"authentication_date,omitempty"` + ChallengeIndicator *common.ChallengeIndicator `json:"challenge_indicator,omitempty"` + Optimization *Optimization `json:"optimization,omitempty"` + Certificates *DsPublicKeys `json:"certificates,omitempty"` + Approved bool `json:"approved,omitempty"` + TransactionType TransactionType `json:"transaction_type,omitempty"` + Ds *Ds `json:"ds,omitempty"` + Acs *Acs `json:"acs,omitempty"` + ResponseCode ResponseCode `json:"response_code,omitempty"` + ResponseStatusReason string `json:"response_status_reason,omitempty"` + Pareq string `json:"pareq,omitempty"` + Cryptogram string `json:"cryptogram,omitempty"` + Eci string `json:"eci,omitempty"` + Xid string `json:"xid,omitempty"` + CardholderInfo string `json:"cardholder_info,omitempty"` + CustomerIp string `json:"customer_ip,omitempty"` + Exemption *ThreeDsExemption `json:"exemption,omitempty"` + FlowType common.ThreeDsFlowType `json:"flow_type,omitempty"` + SchemeInfo *SchemeInfo `json:"scheme_info,omitempty"` + Links map[string]common.Link `json:"_links,omitempty"` } GetSessionResponse struct { @@ -107,6 +142,8 @@ type ( StatusReason StatusReason `json:"status_reason,omitempty"` Approved bool `json:"approved,omitempty"` ProtocolVersion string `json:"protocol_version,omitempty"` + AccountInfo *CardholderAccountInfo `json:"account_info,omitempty"` + MerchantRiskInfo *MerchantRiskInfo `json:"merchant_risk_info,omitempty"` Reference string `json:"reference,omitempty"` TransactionType TransactionType `json:"transaction_type,omitempty"` NextActions []NextAction `json:"next_actions,omitempty"` @@ -133,10 +170,19 @@ func (r *SessionResponse) MapResponse(response *SessionDetails) { } type ( + SessionsCardMetadataResponse struct { + CardType common.CardType `json:"card_type"` + CardCategory common.CardCategory `json:"card_category"` + IssuerName string `json:"issuer_name"` + IssuerCountry common.Country `json:"issuer_country"` + ProductId string `json:"product_id"` + ProductType string `json:"product_type"` + } + CardInfo struct { - InstrumentId string `json:"instrument_id,omitempty"` - Fingerprint string `json:"fingerprint,omitempty"` - Metadata map[string]string `json:"metadata,omitempty"` + InstrumentId string `json:"instrument_id,omitempty"` + Fingerprint string `json:"fingerprint,omitempty"` + Metadata *SessionsCardMetadataResponse `json:"metadata,omitempty"` } DsPublicKeys struct { @@ -172,8 +218,8 @@ type ( } TrustedBeneficiary struct { - Status string `json:"status,omitempty"` - Source string `json:"source,omitempty"` + Status TrustedBeneficiaryStatusType `json:"status,omitempty"` + Source string `json:"source,omitempty"` } SchemeInfo struct { diff --git a/sessions/sources/session_sources.go b/sessions/sources/session_sources.go index 138b030..14b3598 100644 --- a/sessions/sources/session_sources.go +++ b/sessions/sources/session_sources.go @@ -16,12 +16,12 @@ const ( type SessionScheme string const ( - Visa SessionScheme = "visa" - Mastercard SessionScheme = "mastercard" - Jcb SessionScheme = "jcb" Amex SessionScheme = "amex" - Diners SessionScheme = "diners" CartesBancaires SessionScheme = "cartes_bancaires" + Diners SessionScheme = "diners" + Jcb SessionScheme = "jcb" + Mastercard SessionScheme = "mastercard" + Visa SessionScheme = "visa" ) type ( @@ -45,7 +45,7 @@ type ( ExpiryMonth int `json:"expiry_month,omitempty"` ExpiryYear int `json:"expiry_year,omitempty"` Name string `json:"name,omitempty"` - Stored bool `json:"stored,omitempty"` + Stored bool `json:"stored,omitempty" default:"false"` StoreForFutureUse bool `json:"store_for_future_use,omitempty"` } diff --git a/test/reports_test.go b/test/reports_test.go index 4f4fda5..93d6151 100644 --- a/test/reports_test.go +++ b/test/reports_test.go @@ -13,12 +13,13 @@ import ( "github.com/checkout/checkout-sdk-go/reports" ) -var ( - report *reports.ReportResponse -) +func setupReportTest(t *testing.T) *reports.ReportResponse { + t.Log("Setting up before the reports test...") + return getReportId(t) +} -func TestSetupReports(t *testing.T) { - report = getReportId(t) +func teardownReportTest(t *testing.T) { + t.Log("Tearing down after the reports test...") } func TestGetAllReports(t *testing.T) { @@ -72,6 +73,9 @@ func TestGetAllReports(t *testing.T) { } func TestGetReportDetails(t *testing.T) { + report := setupReportTest(t) + defer teardownReportTest(t) + cases := []struct { name string reportId string @@ -114,6 +118,10 @@ func TestGetReportDetails(t *testing.T) { } func TestGetReportFile(t *testing.T) { + t.Skip("unavailable") + report := setupReportTest(t) + defer teardownReportTest(t) + cases := []struct { name string reportId string diff --git a/test/sessions_test.go b/test/sessions_test.go index f5e1110..0012891 100644 --- a/test/sessions_test.go +++ b/test/sessions_test.go @@ -68,13 +68,68 @@ func TestRequestSession(t *testing.T) { } } -func TestGetSessionDetails(t *testing.T) { - t.Skip("not available") +func TestGetSessionDetailsBrowser(t *testing.T) { session := createSession(t, getNonHostedSession(getBrowserChannel(), sessions.Payment, common.NoPreference, sessions.GoodsService)) + cases := []struct { + name string + sessionId string + sessionSecret string + checker func(*sessions.GetSessionResponse, error) + }{ + { + name: "when session exists return session details - with OAuth", + sessionId: session.Created.Id, + checker: func(response *sessions.GetSessionResponse, err error) { + assert.Nil(t, err) + assert.NotNil(t, response) + assert.Equal(t, http.StatusOK, response.HttpMetadata.StatusCode) + assert.Equal(t, session.Created.Id, response.Id) + assert.Equal(t, session.Created.SessionSecret, response.SessionSecret) + }, + }, + { + name: "when session exists return session details - with session secret", + sessionId: session.Created.Id, + sessionSecret: session.Created.SessionSecret, + checker: func(response *sessions.GetSessionResponse, err error) { + assert.Nil(t, err) + assert.NotNil(t, response) + assert.Equal(t, http.StatusOK, response.HttpMetadata.StatusCode) + assert.Equal(t, session.Created.Id, response.Id) + }, + }, + { + name: "when session is inexistent then return error", + sessionId: "sid_av6o4xl4h7yejkliycvn67euay", + checker: func(response *sessions.GetSessionResponse, err error) { + assert.Nil(t, response) + assert.NotNil(t, err) + errChk := err.(errors.CheckoutAPIError) + assert.Equal(t, http.StatusNotFound, errChk.StatusCode) + }, + }, + } + + client := OAuthApi().Sessions + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + tc.checker(client.GetSessionDetails(tc.sessionId, tc.sessionSecret)) + }) + } +} + +func TestGetSessionDetailsMerchantInitiated(t *testing.T) { + t.Skip("unavailable") + session := createSession(t, getNonHostedSession(getMerchantInitiated(), + sessions.Payment, + common.NoPreference, + sessions.GoodsService)) + cases := []struct { name string sessionId string @@ -125,7 +180,6 @@ func TestGetSessionDetails(t *testing.T) { } func TestUpdateSession(t *testing.T) { - t.Skip("not available") session := createSession(t, getHostedSession()).Accepted cases := []struct { @@ -161,7 +215,7 @@ func TestUpdateSession(t *testing.T) { }, { name: "when updating inexistent session then return error", - sessionId: "not_found", + sessionId: "sid_av6o4xl4h7yejkliycvn67euay", request: getBrowserChannel(), checker: func(response *sessions.GetSessionResponse, err error) { assert.Nil(t, response) @@ -182,7 +236,6 @@ func TestUpdateSession(t *testing.T) { } func TestUpdate3dsMethodCompletion(t *testing.T) { - t.Skip("not available") session := createSession(t, getHostedSession()).Accepted cases := []struct { @@ -222,7 +275,7 @@ func TestUpdate3dsMethodCompletion(t *testing.T) { }, { name: "when updating inexistent session then return error", - sessionId: "not_found", + sessionId: "sid_av6o4xl4h7yejkliycvn67euay", request: sessions.ThreeDsMethodCompletionRequest{ ThreeDsMethodCompletion: common.Y, }, @@ -304,6 +357,13 @@ func getBrowserChannel() channels.Channel { return c } +func getMerchantInitiated() channels.Channel { + c := channels.NewMerchantInitiatedSession() + c.RequestType = channels.RecurringTransaction + + return c +} + func getAppChannel() channels.Channel { c := channels.NewAppSession() c.SdkAppId = "dbd64fcb-c19a-4728-8849-e3d50bfdde39" diff --git a/workflows/client_test.go b/workflows/client_test.go index 5e5a998..dbdfb61 100644 --- a/workflows/client_test.go +++ b/workflows/client_test.go @@ -1,7 +1,6 @@ package workflows import ( - "github.com/checkout/checkout-sdk-go/workflows/reflows" "net/http" "testing" @@ -15,6 +14,7 @@ import ( "github.com/checkout/checkout-sdk-go/workflows/actions" "github.com/checkout/checkout-sdk-go/workflows/conditions" "github.com/checkout/checkout-sdk-go/workflows/events" + "github.com/checkout/checkout-sdk-go/workflows/reflows" ) func TestCreateWorkflow(t *testing.T) {