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/order-item.proto";
import "wix/api/entity.proto";
import "wix/api/annotations.proto";
import "wix/api/permissions.proto";
import "wix/api/validations.proto";

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

service PayPalPaymentMethodService {

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

    // Start PayPal checkout for express integration
    rpc CreateCheckout(CreateCheckoutRequest) returns (CheckoutResponse) {
        option (google.api.http) = {
            post: "/api/payments/v2/accounts/{account_id}/paypal-checkout"
        };
    }

    // Update PayPal checkout for express integration
    rpc UpdateCheckout(UpdateCheckoutRequest) returns (CheckoutResponse) {
        option (google.api.http) = {
            put: "/api/payments/v2/accounts/{account_id}/paypal-checkout/{order_id}"
        };
    }

    // Get shipping details from PayPal
    rpc GetPaymentDetails(GetPaymentDetailsRequest) returns (PaymentDetailsResponse) {
        option (google.api.http) = {
            get: "/api/payments/v2/accounts/{account_id}/paypal-checkout/{order_id}/payment-details"
        };
    }
}

message AmountBreakdown {

    google.protobuf.DoubleValue items_total = 1;

    google.protobuf.DoubleValue shipping = 2;

    google.protobuf.DoubleValue tax = 3;

    google.protobuf.DoubleValue discount = 4;
}

message ShippingOption {

    string name = 1;

    double amount = 2;
}

message CreateCheckoutRequest {
    // Account id for which checkout should be started
    //
    // For Wix TPAs account_id is pair of `appId:instanceId`.
    string account_id = 1;

    // amount currency, 3-letter
    string currency = 2;

    // total amount
    double total_amount = 3;

    // amount breakdown
    AmountBreakdown amount_breakdown = 4;

    // request shipping, default false
    bool request_shipping = 5;

    // purchase items
    repeated OrderItem order_items = 6;

    // checkout session id, must be GUID
    google.protobuf.StringValue checkout_session = 7 [(wix.api.format) = GUID];
}

message UpdateCheckoutRequest {
    // Account id for which checkout should be started
    //
    // For Wix TPAs account_id is pair of `appId:instanceId`.
    string account_id = 1;

    // PayPal token
    string order_id = 2;

    // amount currency, 3-letter
    string currency = 3;

    // total amount
    double total_amount = 4;

    // amount breakdown
    AmountBreakdown amount_breakdown = 5;

    // request shipping, default false
    bool request_shipping = 6;

    // shipping options
    repeated ShippingOption shipping_options = 7;

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

    // Cashier order id
    google.protobuf.StringValue cashier_order_id = 9 [(wix.api.format) = GUID];
}

message CheckoutResponse {
    // PayPal token
    string order_id = 1;

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

    // Cashier order id
    google.protobuf.StringValue cashier_order_id = 3 [(wix.api.format) = GUID];
}

message GetPaymentDetailsRequest {
    // Account id for which checkout should be started
    //
    // For Wix TPAs account_id is pair of `appId:instanceId`.
    string account_id = 1;

    // PayPal token
    string order_id = 2;

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

    // Cashier order id
    google.protobuf.StringValue cashier_order_id = 4 [(wix.api.format) = GUID];
}

message PaymentDetailsResponse {

    PayPalBillingAddress billing_address = 1;

    PayPalShippingAddress shipping_address = 2;

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

    // Cashier order id
    google.protobuf.StringValue cashier_order_id = 9 [(wix.api.format) = GUID];
}

message PayPalBillingAddress {

    string country_code = 1;

    string first_name = 2[(.wix.api.pii) = true];

    string last_name = 3[(.wix.api.pii) = true];

    string email = 4[(.wix.api.pii) = true];

    string phone = 5[(.wix.api.pii) = true];

    string state = 6;
}

message PayPalShippingAddress {
    // 2 letter country code
    string country_code = 1;

    string state = 2;

    string city = 3;

    string address_line1 = 4[(.wix.api.pii) = true];

    string address_line2 = 5[(.wix.api.pii) = true];

    string postal_code = 6[(.wix.api.pii) = true];

    string full_name = 7[(.wix.api.pii) = true];

    string phone = 8[(.wix.api.pii) = true];
}
