<commit_before>// Copyright 2014 <NAME>. All rights reserved.
// Use of this source code is governed by a GPL
// license that can be found in the LICENSE file.

package mango

import (
	"encoding/json"
	"errors"
	"fmt"
	"net/url"
)

const (
	TransactionNatureRegular     = "REGULAR"
	TransactionNatureRepudiation = "REPUDIATION"
	TransactionNatureRefund      = "REFUND"
	TransactionNature            = "SETTLEMENT"
)

const (
	TransactionStatusCreated   = "CREATED"
	TransactionStatusSucceeded = "SUCCEEDED"
	TransactionStatusFailed    = "FAILED"
)

const (
	TransactionTypePayIn    = "PAYIN"
	TransactionTypeTransfer = "TRANSFER"
	TransactionTypePayOut   = "PAYOUT"
)

const (
	PayInPaymentTypeCard          = "CARD"
	PayInPaymentTypeDirectDebit   = "DIRECT_DEBIT"
	PayInPaymentTypePreauthorized = "PREAUTHORIZED"
	PayInPaymentTypeBankWire      = "BANK_WIRE"
)

const (
	PayInExecutionTypeWeb    = "WEB"
	PayInExecutionTypeDirect = "DIRECT"
)

const (
	CardTypeCBVisaMasterCard = "CB_VISA_MASTERCARD"
	CardTypeAmex             = "AMEX"
	CardTypeDiners           = "DINERS"
	CardTypeMasterPass       = "MASTERPASS"
	CardTypeMaestro          = "MAESTRO"
	CardTypeP24              = "P24"
	CardTypeIdeal            = "IDEAL"
	CardTypeBcMC             = "BCMC"
	CardTypePaylib           = "PAYLIB"
)

const (
	SecureModeDefault = "DEFAULT"
	SecureModeForce   = "FORCE"
)

const (
	DirectDebitTypeSofort  = "SOFORT"
	DirectDebitTypeELV     = "ELV"
	DirectDebitTypeGiroPay = "GIROPAY"
)

// Custom error returned in case of failed payIn.
type ErrPayInFailed struct {
	payinId string
	msg     string
}

func (e *ErrPayInFailed) Error() string {
	return fmt.Sprintf("payIn %s failed: %s ", e.payinId, e.msg)
}

type TemplateUrlOptions struct {
	Payline string `json:"PAYLINE"`
}

// PayIn holds common fields to all MangoPay's supported payment means
// (through web, direct, preauthorized, bank wire).
type PayIn struct {
	ProcessReply
	AuthorId         string
	CreditedUserId   string
	DebitedFunds     Money
	Fees             Money
	CreditedWalletId string
	SecureMode       string
	CreditedFunds    Money
	Type             string // PAY_IN, PAY_OUT or TRANSFER
	Nature           string // REGULAR, REFUND or REPUDIATION<commit_msg>Export ErrPayInFailed fields<commit_after>// Copyright 2014 <NAME>. All rights reserved.
// Use of this source code is governed by a GPL
// license that can be found in the LICENSE file.

package mango

import (
	"encoding/json"
	"errors"
	"fmt"
	"net/url"
)

const (
	TransactionNatureRegular     = "REGULAR"
	TransactionNatureRepudiation = "REPUDIATION"
	TransactionNatureRefund      = "REFUND"
	TransactionNature            = "SETTLEMENT"
)

const (
	TransactionStatusCreated   = "CREATED"
	TransactionStatusSucceeded = "SUCCEEDED"
	TransactionStatusFailed    = "FAILED"
)

const (
	TransactionTypePayIn    = "PAYIN"
	TransactionTypeTransfer = "TRANSFER"
	TransactionTypePayOut   = "PAYOUT"
)

const (
	PayInPaymentTypeCard          = "CARD"
	PayInPaymentTypeDirectDebit   = "DIRECT_DEBIT"
	PayInPaymentTypePreauthorized = "PREAUTHORIZED"
	PayInPaymentTypeBankWire      = "BANK_WIRE"
)

const (
	PayInExecutionTypeWeb    = "WEB"
	PayInExecutionTypeDirect = "DIRECT"
)

const (
	CardTypeCBVisaMasterCard = "CB_VISA_MASTERCARD"
	CardTypeAmex             = "AMEX"
	CardTypeDiners           = "DINERS"
	CardTypeMasterPass       = "MASTERPASS"
	CardTypeMaestro          = "MAESTRO"
	CardTypeP24              = "P24"
	CardTypeIdeal            = "IDEAL"
	CardTypeBcMC             = "BCMC"
	CardTypePaylib           = "PAYLIB"
)

const (
	SecureModeDefault = "DEFAULT"
	SecureModeForce   = "FORCE"
)

const (
	DirectDebitTypeSofort  = "SOFORT"
	DirectDebitTypeELV     = "ELV"
	DirectDebitTypeGiroPay = "GIROPAY"
)

// ErrPayInFailed is custom error returned in case of failed payIn.
type ErrPayInFailed struct {
	ID  string
	Msg string
}

func (e *ErrPayInFailed) Error() string {
	return fmt.Sprintf("payIn %s failed: %s ", e.ID, e.Msg)
}

type TemplateUrlOptions struct {
	Payline string `json:"PAYLINE"`
}

// PayIn holds common fields to all MangoPay's supported payment means
// (through web, direct, preauthorized, bank wire).
type PayIn struct {
	ProcessReply
	AuthorId         string
	CreditedUserId   string
	DebitedFunds     Money
	Fees             Money
	CreditedWalletId string
	SecureMode       string
	CreditedFunds    Money
	Type             string // PAY_IN, PAY_OUT or TRANSFER
	Nature           string // REGULAR, REFUND or REPUDIATION
{'fraction_non_alphanumeric': 0.08087578194816801, 'fraction_numerical': 0.0035746201966041107, 'mean_word_length': 3.2156308851224105, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1383346', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1520, 'n_words': 363}