syntax = "proto3";

package wix.payment.api.pay.v3;

import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";
import "wix/api/annotations.proto";
import "wix/api/validations.proto";
import "wix/common/address.proto";
import "wix/payment/api/pay/v3/resources/payment-details.proto";

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

message Transaction {

    // Transaction ID
    string id                                                       = 1;

    // Provider transaction ID
    google.protobuf.StringValue provider_transaction_id             = 2;

    // Amount and currency of transaction
    CurrencyAmount amount                                           = 3;

    // Refunded amount and currency of transaction
    CurrencyAmount refundedAmount                                   = 4;

    // Updated transaction status
    TransactionStatus status                                        = 5;

    // Reason provided for status change
    google.protobuf.StringValue reason_code                         = 6;

    // Payment method
    string payment_method                                           = 7;

    // Payment service provider
    string payment_provider                                         = 8;

    // Customer's billing address (optional)
    wix.common.Address billing_address                              = 9;

    // Customer's billing address - contact details (optional)
    wix.common.FullAddressContactDetails billing_address_contacts   = 10;

    // Details of subscription, which (if) the transaction is a part of
    RecurringPaymentDetails recurring_payment_details               = 11;

    // Map with payment method data
    oneof payment_method_data {
        CreditCardPaymentMethodData credit_card_payment_method_data = 101;
    }

    // The details of a payment method account.
    AccountInfo payment_method_account_info                         = 102;

    // Transaction creation date
    google.protobuf.Timestamp created_at                            = 12;

    // Total number of installments 
    int32 installments                                              = 13;

    // Scheduled action for this transaction
    ScheduledAction scheduled_action                                = 14;

    // order id associated with the transaction on the vertical side
    google.protobuf.StringValue vertical_order_id                   = 15 [(wix.api.minLength) = 1, (wix.api.maxLength) = 100];

    enum TransactionStatus {
        UNDEFINED           = 0;
        APPROVED            = 1;
        PENDING             = 2;
        PENDING_MERCHANT    = 3;
        CANCELED            = 4;
        DECLINED            = 5;
        REFUNDED            = 6;
        PARTIALLY_REFUNDED  = 7;
        AUTHORIZED          = 8;
        VOIDED              = 9;
    }
}

message RecurringPaymentDetails {
    // Current cycle number (Recurring payments only)
    int32 cycle_number = 1;
}

message CreditCardPaymentMethodData {
    // Card issuing network
    string network              = 1;

    // Card number with only bin and last4 positions showed (non-PCI data)
    string masked_credit_card   = 2[(.wix.api.pii) = true];

    // Card holder's full name specified on the card.
    string holder_name          = 3[(.wix.api.pii) = true];

    // Card expiration month.
    string expiry_month         = 4;

    // Card expiration year.
    google.protobuf.StringValue expiry_year = 6 [(wix.api.minLength) = 4, (wix.api.maxLength) = 4];

    // Card last 4 digits.
    google.protobuf.StringValue last_four_digits = 5 [(wix.api.pii) = true, (wix.api.minLength) = 4, (wix.api.maxLength) = 4];

    // Card BIN (Bank Identification Number). It's the first 4-8 digits of a card number.
    google.protobuf.StringValue bin = 7 [(wix.api.minLength) = 4, (wix.api.maxLength) = 8];
}

message AccountInfo {
  // The email of an Account used by Payment Method
  google.protobuf.StringValue email = 1 [(.wix.api.pii) = true, (.wix.api.format) = EMAIL];
}

message ScheduledAction {
    enum ScheduledActionType {
        VOID = 0;
        CAPTURE = 1;
    }
    // type of the action
    ScheduledActionType type = 1;
    // the date and time of the action
    google.protobuf.Timestamp execution_date = 2;
}
