//flynt-disable renamed-field-breaking-change, field-type-breaking-change, deleted-field-enum-reserved
syntax = "proto3";

package wix.payment.api.pay.v2;

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

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

service PaymentMethodService {

    option (wix.api.service_entity).message = "wix.payment.api.pay.v2.PaymentMethod";

    // Returns all available payment methods for a specified account or order.
    //
    // **Auth rules**
    //
    // Requires person or server identity to be present.
    //
    // Server identity has permissions to view payment methods without any
    // additional rules.
    //
    // Person identity has permissions to view payment methods without any
    // additional rules.
    //
    // You can find more information about authentication and authorization in a
    // separate [guide][1].
    //
    // **Error responses**
    //
    // - 401 - person identity and a server identity are both missing.
    // - 403 - passed identity does not have permission to perform this action.
    //
    //   [1]: ../../guides/Authentication%20and%20authorization
    rpc List(ListPaymentMethodsRequest) returns (ListPaymentMethodsResponse) {
        option (google.api.http) = {
            get: "/api/payments/v2/accounts/{account_id}/payment-methods"
            additional_bindings {
                get: "/api/payments/v2/orders/{order_id}/payment-methods"
            }
            additional_bindings {
                get: "/api/payments/v2/payment-methods"
            }
        };
    };

    // Returns a specific payment method for a specified account or order. The
    // payment method includes details on what is supported by this payment
    // method, as well as which payment provider is connected to it, and what
    // mandatory fields it requires.
    //
    // **Auth rules**
    //
    // Requires person or server identity to be present.
    //
    // Server identity has permissions to view the order without any additional
    // rules.
    //
    // Person identity has permissions to view payment methods without any
    // additional rules.
    //
    // You can find more information about authentication and authorization in a
    // separate [guide][1].
    //
    // **Error responses**
    //
    // - 401 - person identity and a server identity are both missing.
    // - 403 - passed identity does not have permission to perform this action.
    //
    //   [1]: ../../guides/Authentication%20and%20authorization
    //flynt-disable crud-add-get-annotation
    rpc Get(GetPaymentMethodRequest) returns (GetPaymentMethodResponse) {
        option (google.api.http) = {
            get: "/api/payments/v2/accounts/{account_id}/payment-methods/{payment_method}"
            additional_bindings {
                get: "/api/payments/v2/orders/{order_id}/payment-methods/{payment_method}"
            }
        };
    };

    rpc ListExpressPaymentMethods (ListExpressPaymentMethodsRequest) returns (ListExpressPaymentMethodsResponse) {
        option (google.api.http) = {
            get: "/api/payments/v2/accounts/{account_id}/express-payment-methods"
        };
    };

    // returns available payment methods with BNPL
    rpc ListBuyNowPayLaterMethods(ListBuyNowPayLaterMethodsRequest) returns (ListBuyNowPayLaterMethodsResponse) {
        option (google.api.http) = {
            get: "/api/payments/v2/accounts/{account_id}/bnpl/payment-methods"
        };
    };

    // returns single available payment method with BNPL by id
    rpc GetBuyNowPayLaterMethod(GetBuyNowPayLaterMethodRequest) returns (GetBuyNowPayLaterMethodResponse) {
        option (google.api.http) = {
            get: "/api/payments/v2/accounts/{account_id}/bnpl/payment-methods/{payment_method}"
        };
    };

    // Get SavedPaymentMethodDetails by agreementId
    rpc GetSavedPaymentMethodDetailsByAgreementId(GetSavedPaymentMethodDetailsByAgreementIdRequest) returns (GetSavedPaymentMethodDetailsByAgreementIdResponse) {
        option (google.api.http) = {
            get: "/api/payments/v2/payment-agreements/{payment_agreement_id}/payment-method"
        };
    }
}

message ListPaymentMethodsRequest {
    // Account id for which available payment methods are requested.
    //
    // For Wix TPAs account_id is pair of `appId:instanceId`.
    string account_id                               = 1;

    // order id for which available payment methods are requested
    string order_id                                 = 2;

    // three-letters country code (ISO 3166-1 alpha-3) for which settings are returned (optional)
    string country                                  = 3;

    // amount of payment
    google.protobuf.StringValue amount              = 4 [(.wix.api.format) = DECIMAL_VALUE, (.wix.api.decimalValue).maxScale = 8];

    // currency of payment
    google.protobuf.StringValue currency            = 16 [(.wix.api.format) = CURRENCY];

    // three-letters locale code for which settings are returned (optional)
    google.protobuf.StringValue locale              = 5  [(wix.api.format) = LANGUAGE];

    Charge.ChargeIntent charge_intent               = 6;

    // force Offline payment method is enabled / disabled
    google.protobuf.BoolValue allow_manual_payment  = 7;

    // filter methods which support merchant initiated transactions (optional)
    bool merchant_initiated                         = 8;

    // return saved methods
    bool return_saved_methods                       = 9;

    // return Payment Agreement (if exists) for Saved Method
    bool return_payment_agreement                   = 10;

    //flynt-disable renamed-field-breaking-change
    // return only payment methods which support delayed capture
    bool support_delayed_capture                    = 11;

    // indicate that saving payment method for merchant use is enabled
    bool merchant_use_save_enabled                  = 12;

    // buyer's contactId
    // it's required to display saved payment methods that are allowed for MIT in case contact is a site member
    google.protobuf.StringValue buyer_contact_id    = 13;

    // return only payment methods which support Setup Future Usages option
    bool support_setup_future_usages                = 14;
}

message ListPaymentMethodsResponse {
    // available payment methods
    repeated PaymentMethod payment_methods = 1;
}

message GetPaymentMethodRequest {
    // Account id for which payment method is requested.
    //
    // For Wix TPAs account_id is pair of `appId:instanceId`.
    string account_id                   = 1;

    // order id for which payment method is requested
    string order_id                     = 2;

    // requested payment method
    string payment_method               = 3;

    // three-letters country code (ISO 3166-1 alpha-3) for which settings are returned (optional)
    string country                      = 4;

    // amount of payment
    google.protobuf.StringValue amount  = 5 [(.wix.api.format) = DECIMAL_VALUE, (.wix.api.decimalValue).maxScale = 8];

    // currency of payment
    google.protobuf.StringValue currency = 10 [(.wix.api.format) = CURRENCY];

    // three-letters locale code for which settings are returned (optional)
    google.protobuf.StringValue locale  = 6[(wix.api.format) = LANGUAGE];

    Charge.ChargeIntent charge_intent   = 7;

    // indicate that saving payment method for merchant use is enabled
    bool merchant_use_save_enabled      = 8;

    // return payment method only if it supports Setup Future Usages option
    bool support_setup_future_usages    = 9;
}

message GetPaymentMethodResponse {
    // requested payment method
    PaymentMethod payment_method = 1;
}

message ListExpressPaymentMethodsRequest {
    // Account id for which available payment methods are requested.
    //
    // For Wix TPAs account_id is pair of `appId:instanceId`.
    string account_id                    = 1;

    // amount of payment
    google.protobuf.StringValue amount   = 2 [(.wix.api.format) = DECIMAL_VALUE, (.wix.api.decimalValue).maxScale = 8];

    // currency of payment
    google.protobuf.StringValue currency = 3 [(.wix.api.format) = CURRENCY];
}

message ListExpressPaymentMethodsResponse {
    repeated ExpressPaymentMethod payment_methods = 1;
}

message ListBuyNowPayLaterMethodsRequest {
    // Account id for which payment method is requested.
    //
    // For Wix TPAs account_id is pair of `appId:instanceId`.
    string account_id               = 1;

    // amount of payment
    string amount                   = 2 [(.wix.api.format) = DECIMAL_VALUE, (.wix.api.decimalValue).maxScale = 8];

    // locale language
    string language                 = 3 [(wix.api.format) = LANGUAGE];

    // currency of payment
    string currency                 = 4 [(wix.api.format) = CURRENCY];

    // return only payment methods which support delayed capture
    bool support_delayed_capture    = 5;
}

message ListBuyNowPayLaterMethodsResponse {
    repeated BuyNowPayLaterMethod payment_methods = 1;
}

message GetBuyNowPayLaterMethodRequest {
    // Account id for which payment method is requested.
    //
    // For Wix TPAs account_id is pair of `appId:instanceId`.
    string account_id       = 1;

    // amount of payment
    string amount           = 2 [(.wix.api.format) = DECIMAL_VALUE, (.wix.api.decimalValue).maxScale = 8];

    // locale language
    string language         = 3 [(wix.api.format) = LANGUAGE];

    // requested payment method
    string payment_method   = 4;

    // currency of payment
    string currency         = 5 [(wix.api.format) = CURRENCY];
}

message GetBuyNowPayLaterMethodResponse {
    BuyNowPayLaterMethod payment_method = 1;
}

message GetExternalRecurringAvailabilityRequest {}

message GetExternalRecurringAvailabilityResponse {
    // credit card available
    bool available = 1 [deprecated = true];

    // payPal available
    google.protobuf.BoolValue payPal_available = 2;
}

message GetSavedPaymentMethodDetailsByAgreementIdRequest {
    string payment_agreement_id = 1;
}

message GetSavedPaymentMethodDetailsByAgreementIdResponse {
    SavedPaymentMethodDetails saved_payment_method_details = 1;
}
