From 129eb9be6664ce7d4cb090112f04dae4cebe939c Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Wed, 27 Jun 2018 12:42:00 -0700 Subject: [PATCH] paymentservice: money proto migration the logs will reflect full nanos representation, I'm not sure how to divide this by 10000000 and left pad a zero (%02d). Signed-off-by: Ahmet Alp Balkan --- src/paymentservice/charge.js | 2 +- src/paymentservice/proto/demo.proto | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/paymentservice/charge.js b/src/paymentservice/charge.js index aa6c96d..fe6d266 100644 --- a/src/paymentservice/charge.js +++ b/src/paymentservice/charge.js @@ -58,7 +58,7 @@ module.exports = function charge(request) { throw new ExpiredCreditCard(cardNumber.replace('-', ''), month, year); console.log(`Transaction processed: ${cardType} ending ${cardNumber.substr(-4)} \ - Amount: ${amount.currency_code}${amount.amount.decimal}.${amount.amount.fractional}`) + Amount: ${amount.currency_code}${amount.units}.${amount.nanos}`) return { transaction_id: uuid() } } diff --git a/src/paymentservice/proto/demo.proto b/src/paymentservice/proto/demo.proto index ffd0518..0c3fdf2 100644 --- a/src/paymentservice/proto/demo.proto +++ b/src/paymentservice/proto/demo.proto @@ -63,7 +63,7 @@ message Product { string name = 2; string description = 3; string picture = 4; - MoneyAmount price_usd = 5; + Money price_usd = 5; } message ListProductsResponse { @@ -95,7 +95,7 @@ message GetQuoteRequest { } message GetQuoteResponse { - MoneyAmount cost_usd = 1; + Money cost_usd = 1; } message ShipOrderRequest { @@ -122,18 +122,22 @@ service CurrencyService { rpc Convert(CurrencyConversionRequest) returns (Money) {} } - -// Describes a money amount without currency. For example, decimal=2 and -// fractional=500 (or fractional=5) makes up 2.5 units. -message MoneyAmount { - uint32 decimal = 1; - uint32 fractional = 2; -} - +// Represents an amount of money with its currency type. message Money { // The 3-letter currency code defined in ISO 4217. string currency_code = 1; - MoneyAmount amount = 2; + + // The whole units of the amount. + // For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar. + int64 units = 2; + + // Number of nano (10^-9) units of the amount. + // The value must be between -999,999,999 and +999,999,999 inclusive. + // If `units` is positive, `nanos` must be positive or zero. + // If `units` is zero, `nanos` can be positive, zero, or negative. + // If `units` is negative, `nanos` must be negative or zero. + // For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000. + int32 nanos = 3; } message GetSupportedCurrenciesResponse {