syntax = "proto3";

package wix.payment.api.pay.v2;

import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";
import "wix/api/validations.proto";

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

message CofIntent {

  oneof intent_type {

    // an on-session payment followed by storing credentials to perform cardholder initiated transactions later (like one-click purchases)
    SetupCofOnSession setup_cof_on_session = 1;

    // an on-session payment followed by storing credentials to perform recurring merchant initiated transactions later (like regular subscription charges)
    SetupCofRecurring setup_cof_recurring = 2;

    // an on-session payment followed by storing credentials to perform unscheduled merchant initiated transactions later (like automatic top-ups)
    SetupCofUnscheduled setup_cof_unscheduled = 3;

    // an on-session cardholder initiated transaction (like a one-click purchase)
    CofOnSession cof_on_session = 4;

    // an off-session recurring merchant initiated transaction (like a regular subscription charge)
    CofRecurring cof_recurring = 5;

    // an off-session unscheduled merchant initiated transaction (like an automatic top-up)
    CofUnscheduled cof_unscheduled = 6;
  }
}

message SetupCofOnSession {

  // keep credentials for subsequent payments on a successful payment
  bool store_payment_credentials = 1;
}

message MandateOptions {

  // a description of the mandate or subscription that is meant to be displayed to the customer
  google.protobuf.StringValue description = 1 [(.wix.api.minLength) = 1, (.wix.api.maxLength) = 1000];

  // payment amount
  Amount amount = 2;

  // specifies time ranges for future payments
  Interval interval = 3;

  // specifies frequency of payments
  Frequency frequency = 4;

  message Amount {

    // amount to be charged for future payments
    double value = 1;

    // if `FIXED`, the `amount` parameter refers to the exact amount to be charged in future payments
    // if `MAXIMUM`, the amount charged can be up to the value passed for the `amount` parameter
    Type type = 2;

    enum Type {
      UNKNOWN = 0;
      FIXED = 1;
      MAXIMUM = 2;
    }
  }

  message Interval {

    // start date of the mandate or subscription
    google.protobuf.Timestamp start_date = 1;

    // end date of the mandate or subscription. If not provided, the mandate will be active until canceled
    google.protobuf.Timestamp end_date = 2;
  }

  message Frequency {

    // the number of intervals between payments. For example, `type=MONTH` and `count=3` indicates one payment every three months
    // maximum of one year interval allowed (1 year, 12 months, or 52 weeks)
    // this parameter is optional only when `type=SPORADIC`
    google.protobuf.UInt32Value count = 1 [(.wix.api.min) = 1, (.wix.api.max) = 365];

    Type type = 2;

    enum Type {
      UNKNOWN = 0;
      DAY = 1;
      WEEK = 2;
      MONTH = 3;
      YEAR = 4;
      SPORADIC = 5;
    }
  }
}

message SetupCofRecurring {

  // keep credentials for subsequent payments on a successful payment
  bool store_payment_credentials = 1;

  // a record of the permission a customer has given to debit his payment method
  MandateOptions mandate_options = 2;
}

message SetupCofUnscheduled {

  // keep credentials for subsequent payments on a successful payment
  bool store_payment_credentials = 1;

  // a record of the permission a customer has given to debit his payment method
  MandateOptions mandate_options = 2;
}

message CofOnSession {
  // deprecated, please use payment agreements instead
  string reference_order_id = 1 [deprecated = true];
}

message CofRecurring {
  // deprecated, please use payment agreements instead
  string reference_order_id = 1 [deprecated = true];
}

message CofUnscheduled {
  // deprecated, please use payment agreements instead
  string reference_order_id = 1 [deprecated = true];
}
