syntax = "proto3";

package wix.payment.api.pay.v2;

import "wix/payment/api/pay/v2/resources/address.proto";
import "wix/payment/api/pay/v2/resources/order-buyer-info.proto";
import "wix/payment/api/pay/v2/resources/order-return-urls.proto";
import "google/protobuf/wrappers.proto";
import "wix/api/validations.proto";
import "wix/api/entity.proto";

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

// Details on how the order was paid.
//
// It's either embedded payment details or an id of the previously saved details.
message Payment {
    oneof payment {
        // details embedded into request
        PaymentDetails details    = 1;
        // id of previously saved details
        string details_id         = 2;
    }
}

// Payment details
message PaymentDetails {

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

    // payment method as returned by [list payment methods][1] (required)
    //
    //  [1]: /cashier-pay/reference/payment-method/.wix.payment.api.pay.v2.-payment-method-service.-list
    string payment_method                            = 1;

    // Availability and limitations of using installements, as imposed by the connected provider (optional, default: 1).
    int32 installments                               = 2;

    // client attributes (optional)
    ClientInfo client_info                           = 3;

    // credit card token (required if `paymentMethod` = `creditCard`), instead use token
    CreditCardToken credit_card_token                = 100 [deprecated=true];

    // token for payment, can be credit card, applePay, payPal or other kind of token.
    // Deprecated, instead use one of payment method details.
    google.protobuf.StringValue token                = 103 [deprecated=true];

    // Any additional data which might be required by providers in order to process payment. This field is not used
    // right now, so leave it blank. Work in progress.
    //
    // Usages:
    // * iDeal.issuerBank - for `com.stripe` provider, when `paymentMethod` is `iDeal`
    // Deprecate, instead use one of payment method details.
    map<string, string> additional_data              = 101 [deprecated=true];

    // billing address providing fields missing from the order (optional)
    Address billing_address                          = 102;

    // checkout type, express or regular
    CheckoutType checkout_type                       = 104;

    // checkout session id, must be GUID
    google.protobuf.StringValue checkout_session     = 105;

    // disposition of redirect target: embedded, in the same window, in a new window
    RedirectTarget redirect_target                   = 106;

    BuyerLocale buyer_info                           = 107;

    //Used for saved credit card
    bool save_payment_method                         = 108;

    google.protobuf.StringValue payment_agreement_id = 109;

    // you may specify id of order these PaymentDetails are used with.
    // if that order has 1 not failed transaction further use of these details won't be possible.
    google.protobuf.StringValue order_id             = 110;

    // allows merchant to use save payment method for unscheduled payments
    bool merchant_use_allowed                        = 111;

    // payment is finalized
    bool confirmed                                   = 112;

    // Cashier charge id
    google.protobuf.StringValue charge_id            = 113 [(wix.api.format) = GUID];

    // Return urls to override existing ones in Order
    OrderReturnUrls return_urls_overrides            = 114;

    oneof payment_method_details {
      // payment with a card online
      CardPayment card                        = 201;

      // payment with a card at a POS
      CardReaderPayment card_reader           = 202;

      // the iDEAL payment system
      IDealPayment ideal                      = 203;

      // the Apple Pay digital wallet
      ApplePayPayment apple_pay               = 204;

      PayPalPayment pay_pal                   = 205;

      // Google Pay
      GooglePayPayment google_pay             = 206;

      // payment with a card using saved card
      SavedCardPayment saved_card_payment     = 207;
    }
}

// Client attributes
message ClientInfo {
    // client device fingerprint (optional)
    google.protobuf.StringValue device_fingerprint = 1;
    // Provider-specific risk data
    map<string, string> risk_provider_data = 2 [(wix.api.maxSize) = 16];
    // Captcha token generated by client after showing Captcha challenge to request initiator
    // Required if Captcha is enabled for the site
    // Exclusions: OneApp
    google.protobuf.StringValue captcha_token = 3;
}

// Credit card token
message CreditCardToken {
    // token string representation (as returned by [cashier credit card tokenizer][1])
    //
    //   [1]: /cashier-credit-card/reference/token
    string token = 1;
}

enum CheckoutType {
    UNKNOWN = 0;
    REGULAR = 1;
    EXPRESS = 2;
}

enum RedirectTarget {
    SAME_WINDOW = 0;
    NEW_WINDOW  = 1;
    EMBEDDED    = 2;
}

message CardPayment {

    // the card number token
    string number_token = 1 [(wix.api.minLength) = 1 /*, (wix.api.maxLength) = ? */];

    // the month of the card expiration date
    uint32 expiry_month = 2 [(wix.api.min) = 1, (wix.api.max) = 12];

    // the full year of the card expiration date
    uint32 expiry_year = 3 [(wix.api.min) = 2000, (wix.api.max) = 2099];

    // the cardholder name printed on the card
    google.protobuf.StringValue holder_name = 4 [(wix.api.minLength) = 1 /*, (wix.api.maxLength) = ? */];

    // the CVV/CVC/CID token
    google.protobuf.StringValue security_code_token = 5 [(wix.api.minLength) = 1 /*, (wix.api.maxLength) = ? */];
}

message IDealPayment {

  // the code of the issuing bank
  string issuing_bank = 1 [(wix.api.minLength) = 1, (wix.api.maxLength) = 100];
}

message GooglePayPayment {
  // the payment token
  string token = 1 [(wix.api.minLength) = 1];
  // Display name of the card
  google.protobuf.StringValue displayName = 3 [(wix.api.minLength) = 1];
  // Network of the card
  google.protobuf.StringValue network = 4 [(wix.api.minLength) = 1];
  // Type of the card
  google.protobuf.StringValue type = 5 [(wix.api.minLength) = 1];
}

message ApplePayPayment {
  // the payment token
  string token = 1 [(wix.api.minLength) = 1 /*, (wix.api.maxLength) = ? */];
  // Display name of the card
  google.protobuf.StringValue displayName = 3 [(wix.api.minLength) = 1 /*, (wix.api.maxLength) = ? */];
  // Network of the card
  google.protobuf.StringValue network = 4 [(wix.api.minLength) = 1 /*, (wix.api.maxLength) = ? */];
  // Type of the card
  google.protobuf.StringValue type = 5 [(wix.api.minLength) = 1 /*, (wix.api.maxLength) = ? */];
}

message CardReaderPayment {

  // the location ID
  google.protobuf.StringValue location_id = 1 [(wix.api.minLength) = 1, (wix.api.maxLength) = 36];

  // the terminal ID
  google.protobuf.StringValue terminal_id = 2 [(wix.api.minLength) = 1, (wix.api.maxLength) = 50];

  // the service ID
  google.protobuf.StringValue service_id = 3 [(wix.api.minLength) = 1, (wix.api.maxLength) = 50];

  // whether create intent only or complete transaction (use this flag only if you know what it means)
  google.protobuf.BoolValue create_intent_only = 4 [deprecated=true];
}

message PayPalPayment {

    google.protobuf.StringValue pay_pal_token = 1;
}

message SavedCardPayment {
  // id of previously saved Payment Method
  string payment_method_id  = 1;

  // the CVV/CVC/CID token
  google.protobuf.StringValue security_code_token = 2;
}
