syntax = "proto3";

package wix.payment.api.pay.v2;

import "wix/payment/api/pay/v2/resources/charge.proto";
import "wix/payment/api/pay/v2/resources/mandatory-field.proto";
import "google/protobuf/wrappers.proto";
import "wix/api/entity.proto";
import "wix/api/annotations.proto";
import "wix/api/validations.proto";


option java_package = "com.wix.payment.api.pay.v2";

// Describing payment method: it's id, provider name, mandatory fields, charget intents and any other additional info.
message PaymentMethod {

    option (wix.api.entity) = {
        fqdn: "wix.cashier.pay.v2.payment_method"
        segment: PUBLIC // no domain events produced
    };

    // unique identifier of payment method
    string payment_method             = 1;
    // Provider which is connected to process the payment method. Note that a payment method can only be connected to
    // one provider.
    //
    // Provider ID (like `net.authorize` or `payPal`) can be used for UI purposes.
    //
    // Checkout [PaymentProviders.scala][1] for the list of defined providers.
    //
    //   [1]: https://github.com/wix-private/cashier/blob/master/payment-services/blackbeard-modules/payment-domain/src/main/scala/com/wixpress/payment/settings/PaymentProviders.scala
    string connected_provider_id      = 2;
    // the method type
    MethodType method_type            = 3;
    // Availability and limitations of using installements, as imposed by the connected provider.
    Installments installments         = 4;

    // Additional info for providers which is needed to integrate payments:

    // * `square` - `squareAppId` and `location`
    // * `offline` - `merchantInstructions`
    map<string, string> additional_info = 6;

    // Fields that need to be provided for payment to pass for the connected provider or the order to which this payment
    // method belongs.
    repeated MandatoryField mandatory_fields = 7;

    // Meaning that the method is currently not available for charage due to problems with 3rd-party provider. You
    // should use this field to reflect the issue on the client side.
    //
    // If you use this method in [charge request][1], server will response with 403.
    //
    //   [1]: .wix.payment.api.pay.v2.-payment-service.-charge
    bool disabled = 8;

    // Charge intents which are supported by this payment method.
    //
    // What kind of payment the buyer wants to perform: A one-time payment, a recurring payment, or an authorize
    // payment - authorize is when the provider reserves the funds from the user’s credit card, but doesn’t actually
    // charge them. This is usually done for ‘booking’ style flows, where the hotel reserves the booking amount but only
    // charges it when the guest arrives. Authorize flow is not fully supported by Cashier yet, work in progress.
    repeated Charge.ChargeIntent supported_charge_intents = 10;

    // method type
    enum MethodType {
        UNDEFINED = 0;
        ONLINE = 1;
        FACE_TO_FACE = 2;
    }

    //link to the method icon
    google.protobuf.StringValue method_icon = 11;

    //link to the method resizable png icon
    google.protobuf.StringValue method_icon_png = 16;

    //title for payment method
    google.protobuf.StringValue method_title = 12;

    bool frameable  = 13;

    bool responsive = 14;

    bool redirectable = 15;

    bool bnpl_support = 18;

    int32 rank = 17;

    bool provider_tokenization = 19;

    google.protobuf.StringValue saved_payment_method_id = 20 [(wix.api.format) = GUID];

    google.protobuf.StringValue payment_agreement_id = 21 [(wix.api.format) = GUID];

    // is saved method primary for this UoU
    google.protobuf.BoolValue primary = 22;

    // is saved method authorized for this specific order
    google.protobuf.BoolValue suggested = 23;

    oneof saved_payment_method_details {
        PayPalDetails pay_pal_details = 24;
        SavedCreditCardDetails saved_credit_card_details = 25;
    }

    enum SavePaymentMethodDisplayOption {
        SHOW_NOTHING = 0;
        SHOW_SAVE_PAYMENT_METHOD_CHECKBOX = 1;
        SHOW_DISCLAIMER = 2;
        SHOW_MERCHANT_SAVE_PAYMENT_METHOD_CHECKBOX = 3;
        SHOW_MERCHANT_DISCLAIMER = 4;
        SHOW_VISITOR_DISCLAIMER = 5;
    }

    //Save Payment Method legal conditions
    SavePaymentMethodDisplayOption save_payment_method_display_option = 26;

    // Allow manual MIT legal conditions
    AllowMerchantUseDisplayOptionEnum.AllowMerchantUseDisplayOption allow_merchant_use_display_option = 27;

    // Credentials, stored by a cardholder when using this payment method type, can be used subsequently by a merchant to perform unscheduled credential-on-file merchant initiated transactions.
    bool unscheduled_mit_support = 28;

    // Indicates that Client have to show Captcha challenge to request initiator to proceed with this Payment Method
    // Captcha validation is expected on further payment with this method
    bool captcha_required = 29;

    // additional payment method details
    oneof payment_method_details {

        // Apple Pay payment method details
        ApplePayPaymentMethodDetails apple_pay   = 30;
    }
}

message ApplePayPaymentMethodDetails {
    // The merchant’s two-letter country code
    string merchant_country                             = 1 [(wix.api.format) = COUNTRY];

    //The payment networks the merchant supports
    repeated CreditCardNetwork supported_networks       = 2 [(wix.api.minSize) = 0, (wix.api.maxSize) = 200];

    //The payment capabilities the merchant supports
    repeated MerchantCapability merchant_capabilities   = 3 [(wix.api.minSize) = 0, (wix.api.maxSize) = 200];
}

message AllowMerchantUseDisplayOptionEnum {
    enum AllowMerchantUseDisplayOption {
        SHOW_NOTHING = 0;
        SHOW_ALLOW_MERCHANT_USE_CHECKBOX = 1;
    }
}

message SavedCreditCardDetails {
    // credit card network (visa, mastercard, amex, jcb)
    google.protobuf.StringValue network      = 1;

    // last 4 digits of credit card number
    string last_four_digits                  = 2;

    // the month of the card expiration date
    google.protobuf.UInt32Value expiry_month = 3 [(wix.api.min) = 1, (wix.api.max) = 12];

    // the full year of the card expiration date
    google.protobuf.UInt32Value expiry_year  = 4 [(wix.api.min) = 2000, (wix.api.max) = 2099];

    // credit card holder's name
    google.protobuf.StringValue holder_name  = 5;
}

message PayPalDetails {
    // Can be an email (obfuscated) of PayPal account
    google.protobuf.StringValue account_name = 1 [(.wix.api.minLength) = 1, (.wix.api.maxLength) = 1000];
}

message SavedPaymentMethodDetails {
    oneof details {
        SavedCreditCardDetails saved_credit_card_details = 1;
        PayPalDetails pay_pal_details = 2;
    }
}

// Availability and limitations of using installements, as imposed by the connected provider.
message Installments {
    // minimum number of installments to use
    int32 min_installments             = 1;
    // maximum number of installments to use
    int32 max_installments             = 2;
    // minimum amount to use installments
    double min_transaction_amount      = 3;
}

message BuyNowPayLaterMethod {
    // unique identifier of payment method
    string payment_method                               = 1;

    // available options for BNPL for UoU
    repeated BuyNowPayLaterOption payment_options       = 2;
    // url of page with BNPL details
    google.protobuf.StringValue infoUrl                 = 3;
    // payment method logos
    BuyNowPayLaterMethodLogo logo                       = 4;
    // payment method promo message
    google.protobuf.StringValue promo_message           = 5;
    // UoU method display rank
    int32 rank                                          = 6;

    // display name of payment provider connected to payment method
    string payment_provider_name                        = 10;

    // payment method promo message
    string bnpl_message                                 = 15;

    // payment method modal page with more BNPL info:
    // terms & conditions, detailed plans, etc
    ModalPage bnpl_modal_page                           = 16;

    // payment provider impression URL to notify when provider BNPL is shown to UoU
    google.protobuf.StringValue provider_impression_url = 17;
}

message BuyNowPayLaterMethodLogo {
    string logo_light   = 1;
    string logo_dark    = 2;
}

message BuyNowPayLaterOption {
    // number of installments
    uint32 installment_count   = 1;
    // amount of each installment
    double installment_amount  = 2;
    // total amount with interest
    double total_amount         = 3;
    // provider commission amount
    double interest_amount      = 4;
}

message ModalPage {
    // page url
    string url                                          = 1;

    // page link text
    string cta_text                                     = 2;

    // display resolution of modal page
    // empty if page is responsive
    PageResolution resolution                           = 3;
}

message PageResolution {
    uint32 height   = 1;
    uint32 width    = 2;
}

message ExpressPaymentMethod {

    google.protobuf.StringValue payment_provider_id = 1 [(wix.api.referenced_entity) = "wix.cashier.settings.v2.payment_provider", (wix.api.minLength) = 1, (wix.api.maxLength) = 255];

    oneof payment_method_details {
        ApplePayExpressPaymentMethodDetails apple_pay   = 10;

        PayPalExpressPaymentMethodDetails pay_pal       = 11;

        GooglePayExpressPaymentMethodDetails google_pay = 12;
    }

    message ApplePayExpressPaymentMethodDetails {
        // The merchant’s two-letter country code
        string merchant_country                             = 1;

        //The payment networks the merchant supports
        repeated CreditCardNetwork supported_networks       = 5;

        //The payment capabilities the merchant supports
        repeated MerchantCapability merchant_capabilities   = 6;
    }

    message GooglePayExpressPaymentMethodDetails {

        string merchant_country                       = 1;

        repeated CreditCardNetwork supported_networks = 5;

        repeated PanType panTypes                     = 6;
    }

    message PayPalExpressPaymentMethodDetails {

        string client_id        = 1;

        string merchant_id      = 2;

        string bn_code          = 3;

        bool credit_enabled     = 4;
    }
}

enum CreditCardNetwork {
    UNDEFINED_NETWORK   = 0;
    AMEX                = 1;
    CARTES_BANCAIRES    = 2;
    CHINA_UNION_PAY     = 3;
    DISCOVER            = 5;
    EFTPOS              = 6;
    ELECTRON            = 7;
    ELO                 = 8;
    INTERAC             = 9;
    JCB                 = 10;
    MADA                = 11;
    MAESTRO             = 12;
    MASTER_CARD         = 13;
    PRIVATE_LABEL       = 14;
    VISA                = 15;
    VPAY                = 16;
    BANCONTACT_CARD     = 17;
}

enum MerchantCapability {
    UNDEFINED_CAPABILITY    = 0;
    SUPPORTS_3DS            = 1;
    SUPPORTS_EMV            = 2;
    SUPPORTS_CREDIT         = 3;
    SUPPORTS_DEBIT          = 4;
}

enum PanType {
    UNDEFINED_TYPE = 0;
    FPAN = 1; // PAN_ONLY
    DPAN = 2; // CRYPTOGRAM_3DS
}
