summaryrefslogtreecommitdiff
path: root/c2ec/wallee-client.go
diff options
context:
space:
mode:
Diffstat (limited to 'c2ec/wallee-client.go')
-rw-r--r--c2ec/wallee-client.go272
1 files changed, 42 insertions, 230 deletions
diff --git a/c2ec/wallee-client.go b/c2ec/wallee-client.go
index 2f304d0..a7f9f14 100644
--- a/c2ec/wallee-client.go
+++ b/c2ec/wallee-client.go
@@ -52,6 +52,11 @@ func (wt *WalleeTransaction) AbortWithdrawal() bool {
strings.EqualFold(string(wt.State), string(StateDecline))
}
+func (wt *WalleeTransaction) FormatPayto() string {
+
+ return fmt.Sprintf("payto://wallee-transaction/%d", wt.ID)
+}
+
func (wt *WalleeTransaction) Bytes() []byte {
reader, err := NewJsonCodec[WalleeTransaction]().Encode(wt)
@@ -112,8 +117,44 @@ func (w *WalleeClient) GetTransaction(transactionId string) (ProviderTransaction
return t, nil
}
+func (sc *WalleeClient) FormatPayto(w *Withdrawal) string {
+
+ return fmt.Sprintf("payto://wallee-transaction/%s", *w.ProviderTransactionId)
+}
+
func (w *WalleeClient) Refund(transactionId string) error {
- return errors.New("not yet implemented")
+
+ call := WALLEE_CREATE_REFUND_API
+ queryParams := map[string]string{
+ WALLEE_API_SPACEID_PARAM_NAME: strconv.Itoa(w.credentials.SpaceId),
+ }
+ url := FormatUrl(call, map[string]string{}, queryParams)
+
+ hdrs, err := w.prepareWalleeHeaders(url, HTTP_GET)
+ if err != nil {
+ return err
+ }
+
+ // TODO generate refund object. needs Completion and Transaction IDs
+ refund := &WalleeRefund{
+ Amount: 10,
+ Completion: 10,
+ ExternalID: "",
+ MerchantReference: "",
+ Reductions: []WalleeLineItemReduction{},
+ Transaction: 10,
+ Type: "",
+ }
+
+ _, status, err := HttpPost[WalleeRefund, any](url, hdrs, refund, NewJsonCodec[WalleeRefund](), nil)
+ if err != nil {
+ LogError("wallee-client", err)
+ return err
+ }
+ if status != HTTP_OK {
+ return errors.New("no result")
+ }
+ return nil
}
func (w *WalleeClient) prepareWalleeHeaders(url string, method string) (map[string]string, error) {
@@ -218,232 +259,3 @@ func calculateWalleeAuthToken(
return base64.StdEncoding.EncodeToString(mac), nil
}
-
-type TransactionState string
-
-const (
- StateCreate TransactionState = "CREATE"
- StatePending TransactionState = "PENDING"
- StateConfirmed TransactionState = "CONFIRMED"
- StateProcessing TransactionState = "PROCESSING"
- StateFailed TransactionState = "FAILED"
- StateAuthorized TransactionState = "AUTHORIZED"
- StateCompleted TransactionState = "COMPLETED"
- StateFulfill TransactionState = "FULFILL"
- StateDecline TransactionState = "DECLINE"
- StateVoided TransactionState = "VOIDED"
-)
-
-type WalleeTransaction struct {
- ProviderTransaction
-
- // acceptHeader contains the header which indicates the language preferences of the buyer.
- AcceptHeader string `json:"acceptHeader"`
-
- // acceptLanguageHeader contains the header which indicates the language preferences of the buyer.
- AcceptLanguageHeader string `json:"acceptLanguageHeader"`
-
- // allowedPaymentMethodBrands is a collection of payment method brand IDs.
- AllowedPaymentMethodBrands []int64 `json:"allowedPaymentMethodBrands"`
-
- // allowedPaymentMethodConfigurations is a collection of payment method configuration IDs.
- AllowedPaymentMethodConfigurations []int64 `json:"allowedPaymentMethodConfigurations"`
-
- // authorizationAmount is the amount authorized for the transaction.
- AuthorizationAmount float64 `json:"authorizationAmount"`
-
- // authorizationEnvironment is the environment in which this transaction was successfully authorized.
- AuthorizationEnvironment string `json:"authorizationEnvironment"`
-
- // authorizationSalesChannel is the sales channel through which the transaction was placed.
- AuthorizationSalesChannel int64 `json:"authorizationSalesChannel"`
-
- // authorizationTimeoutOn is the time on which the transaction will be timed out when it is not at least authorized.
- AuthorizationTimeoutOn time.Time `json:"authorizationTimeoutOn"`
-
- // authorizedOn is the timestamp when the transaction was authorized.
- AuthorizedOn time.Time `json:"authorizedOn"`
-
- // autoConfirmationEnabled indicates whether auto confirmation is enabled for the transaction.
- AutoConfirmationEnabled bool `json:"autoConfirmationEnabled"`
-
- // billingAddress is the address associated with the transaction.
- BillingAddress string `json:"-"`
-
- // chargeRetryEnabled indicates whether charging retry is enabled for the transaction.
- ChargeRetryEnabled bool `json:"chargeRetryEnabled"`
-
- // completedAmount is the total amount which has been captured so far.
- CompletedAmount float64 `json:"completedAmount"`
-
- // completedOn is the timestamp when the transaction was completed.
- CompletedOn time.Time `json:"completedOn"`
-
- // completionBehavior controls when the transaction is completed.
- CompletionBehavior string `json:"completionBehavior"`
-
- // completionTimeoutOn is the timestamp when the transaction completion will time out.
- CompletionTimeoutOn time.Time `json:"completionTimeoutOn"`
-
- // confirmedBy is the user ID who confirmed the transaction.
- ConfirmedBy int64 `json:"confirmedBy"`
-
- // confirmedOn is the timestamp when the transaction was confirmed.
- ConfirmedOn time.Time `json:"confirmedOn"`
-
- // createdBy is the user ID who created the transaction.
- CreatedBy int64 `json:"createdBy"`
-
- // createdOn is the timestamp when the transaction was created.
- CreatedOn time.Time `json:"createdOn"`
-
- // currency is the currency code associated with the transaction.
- Currency string `json:"currency"`
-
- // customerEmailAddress is the email address of the customer.
- CustomerEmailAddress string `json:"customerEmailAddress"`
-
- // customerId is the ID of the customer associated with the transaction.
- CustomerID string `json:"customerId"`
-
- // customersPresence indicates what kind of authentication method was used during authorization.
- CustomersPresence string `json:"customersPresence"`
-
- // deliveryDecisionMadeOn is the timestamp when the decision has been made if a transaction should be delivered or not.
- DeliveryDecisionMadeOn time.Time `json:"deliveryDecisionMadeOn"`
-
- // deviceSessionIdentifier links the transaction with the session identifier provided in the URL of the device data JavaScript.
- DeviceSessionIdentifier string `json:"deviceSessionIdentifier"`
-
- // emailsDisabled indicates whether email sending is disabled for this particular transaction.
- EmailsDisabled bool `json:"emailsDisabled"`
-
- // endOfLife indicates the date from which on no operation can be carried out anymore.
- EndOfLife time.Time `json:"endOfLife"`
-
- // environment is the environment in which the transaction is processed.
- Environment string `json:"environment"`
-
- // environmentSelectionStrategy determines how the environment (test or production) for processing the transaction is selected.
- EnvironmentSelectionStrategy string `json:"environmentSelectionStrategy"`
-
- // failedOn is the timestamp when the transaction failed.
- FailedOn time.Time `json:"failedOn"`
-
- // failedUrl is the URL to which the user will be redirected when the transaction fails.
- FailedURL string `json:"failedUrl"`
-
- // failureReason describes why the transaction failed.
- FailureReason string `json:"failureReason"`
-
- // group is the transaction group associated with the transaction.
- Group string `json:"-"`
-
- // id is the unique identifier for the transaction.
- ID int64 `json:"id"`
-
- // internetProtocolAddress identifies the device of the buyer.
- InternetProtocolAddress string `json:"internetProtocolAddress"`
-
- // internetProtocolAddressCountry is the country associated with the Internet Protocol (IP) address.
- InternetProtocolAddressCountry string `json:"internetProtocolAddressCountry"`
-
- // invoiceMerchantReference is the merchant reference associated with the invoice.
- InvoiceMerchantReference string `json:"invoiceMerchantReference"`
-
- // javaEnabled indicates whether Java is enabled for the transaction.
- JavaEnabled bool `json:"javaEnabled"`
-
- // language is the language linked to the transaction.
- Language string `json:"language"`
-
- // lineItems is a collection of line items associated with the transaction.
- LineItems []string `json:"-"`
-
- // linkedSpaceId is the ID of the space this transaction belongs to.
- LinkedSpaceID int64 `json:"linkedSpaceId"`
-
- // merchantReference is the merchant reference associated with the transaction.
- MerchantReference string `json:"merchantReference"`
-
- // metaData allows storing additional information about the transaction.
- MetaData map[string]string `json:"metaData"`
-
- // parent is the parent transaction associated with this transaction.
- Parent int64 `json:"parent"`
-
- // paymentConnectorConfiguration is the connector configuration associated with the payment.
- PaymentConnectorConfiguration string `json:"-"`
-
- // plannedPurgeDate is the date when the transaction is planned to be permanently removed.
- PlannedPurgeDate time.Time `json:"plannedPurgeDate"`
-
- // processingOn is the timestamp when the transaction is being processed.
- ProcessingOn time.Time `json:"processingOn"`
-
- // refundedAmount is the total amount which has been refunded so far.
- RefundedAmount float64 `json:"refundedAmount"`
-
- // screenColorDepth is the color depth of the screen associated with the transaction.
- ScreenColorDepth string `json:"screenColorDepth"`
-
- // screenHeight is the height of the screen associated with the transaction.
- ScreenHeight string `json:"screenHeight"`
-
- // screenWidth is the width of the screen associated with the transaction.
- ScreenWidth string `json:"screenWidth"`
-
- // shippingAddress is the address associated with the shipping of the transaction.
- ShippingAddress string `json:"-"`
-
- // shippingMethod is the method used for shipping in the transaction.
- ShippingMethod string `json:"shippingMethod"`
-
- // spaceViewId is the ID of the space view associated with the transaction.
- SpaceViewID int64 `json:"spaceViewId"`
-
- // state is the current state of the transaction.
- State TransactionState `json:"state"`
-
- // successUrl is the URL to which the user will be redirected when the transaction succeeds.
- SuccessURL string `json:"successUrl"`
-
- // terminal is the terminal on which the payment was processed.
- Terminal string `json:"-"`
-
- // timeZone is the time zone in which the customer is located.
- TimeZone string `json:"timeZone"`
-
- // token is the token associated with the transaction.
- Token string `json:"-"`
-
- // tokenizationMode controls if and how the tokenization of payment information is applied to the transaction.
- TokenizationMode string `json:"tokenizationMode"`
-
- // totalAppliedFees is the sum of all fees that have been applied so far.
- TotalAppliedFees float64 `json:"totalAppliedFees"`
-
- // totalSettledAmount is the total amount which has been settled so far.
- TotalSettledAmount float64 `json:"totalSettledAmount"`
-
- // userAgentHeader provides the user agent of the buyer.
- UserAgentHeader string `json:"userAgentHeader"`
-
- // userFailureMessage describes why the transaction failed for the end user.
- UserFailureMessage string `json:"userFailureMessage"`
-
- // userInterfaceType defines through which user interface the transaction has been processed.
- UserInterfaceType string `json:"userInterfaceType"`
-
- // version is used for optimistic locking and incremented whenever the object is updated.
- Version int `json:"version"`
-
- // windowHeight is the height of the window associated with the transaction.
- WindowHeight string `json:"windowHeight"`
-
- // windowWidth is the width of the window associated with the transaction.
- WindowWidth string `json:"windowWidth"`
-
- // yearsToKeep is the number of years the transaction will be stored after it has been authorized.
- YearsToKeep int `json:"yearsToKeep"`
-}