注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
已从图片版整理成文字版 包含部分test case 方便大家准备!
Split Tender
Many of Stripe's merchants rely on Stripe Terminal to accept in-person payments at the point of sale. In physical retail, it's common for a customer to cover a purchase with multiple payment methods. For example, they might cover a $100 purchase with a $40 gift card combined with a $60 credit card. This is called a split-tender transaction, and supporting it is a key requirement for retail merchants on Terminal.
For this multi-part question, we will be writing a system to process split-tender payments. When a transaction occurs, the system first deducts from the customer's available gift card balance, then charges the remaining balance to the customer's credit card. Given a chronological stream of payment events, your task is to calculate the correct credit card charge for each transaction. The question is broken down into four parts, each introducing a new event type: gift card expiration, regional credit card surcharges, and complex refund logic.
Function Description
Complete the functionin the editor below.
Function Parameters
: Lines for each event in chronological order. Lines have a format defined by one of three schemas:
- timestamp,ADD_GIFTCARD,customer_id,card_id,amount,valid_before
复制代码- timestamp,CHARGE,charge_id,customer_id,amount,zip_code
复制代码- timestamp,REFUND,charge_id,refund_amount
复制代码
- string surcharge_rates[m]
复制代码 : A list of non-overlapping ZIP code ranges mapped to a surcharge percentage in the format, where start and end are inclusive.
Example:(representing 5%).
General Constraints and Assumptions
- Events are in chronological order by timestamp.
- All event lines are well-formed.
- values are unique acrossevents.
- events always reference a priorevent.
- Eachwill receive at most oneevent.
- values fromevents are unique.
- contains non-overlapping, valid ZIP code ranges.
- values are five-digit numeric strings.
Monetary Representation and Pred for the referenced, including surcharge.Store credit second: Ifexceeds the amount refundable to the credit card, refund the remaining amount as store credit by creating a new gift card for the original customer. The newmust be formatted as. This gift card has no expiration date.Refund-created gift cards participate in futureevents like any other gift card. Refund-created gift cards never expire. When choosing gift cards for a future charge, non-expiring gift cards are used after all valid gift cards with finite expiration timestamps.
Output Format for : Return a flat string containing the amount refunded to the credit card and the amount refunded to the store credit gift card, separated by a single comma:Example Input- events = [
- "1,ADD_GIFTCARD,cust1,gc1,5000,10",
- "2,CHARGE,chg1,cust1,15000,90210",
- "3,REFUND,chg1,12000"
- ]
- surcharge_rates = [
- "90000-99999:0.05"
- ]
复制代码 Example Output- [
- "",
- "10500,gc1:5000",
- "10500,1500" # CC_REFUND, GC_REFUND
- ]
复制代码 Appendix: Additional Test Cases
The following test cases were shown in subsequent debugging screenshots. These are separate from the original problem's four example sections.
Test Case 13
Input:- events = [
- "1,ADD_GIFTCARD,cust_1,gc_1,5000,10",
- "2,CHARGE,chg_1,cust_1,15000,90210",
- "3,REFUND,chg_1,12000"
- ]
- surcharge_rates = ["90000-99999:0.05"]
复制代码 Expected output:- ["", "10500,gc_1:5000", "10500,1500"]
复制代码 Test Case 16
Input:- events = [
- "1,ADD_GIFTCARD,cust_1,gc_1,10000,10",
- "2,CHARGE,chg_1,cust_1,20000,15000",
- "3,REFUND,chg_1,21000",
- "15,CHARGE,chg_2,cust_1,5000,15000",
- "16,ADD_GIFTCARD,cust_1,gc_2,3000,20",
- "17,CHARGE,chg_3,cust_1,9000,15000"
- ]
- surcharge_rates = ["10000-20000:0.10"]
复制代码 Expected output:- [
- "",
- "11000,gc_1:10000",
- "11000,10000",
- "0,REFUND_chg_1:5000",
- "",
- "1100,REFUND_chg_1:5000,gc_2:3000"
- ]
复制代码 新人求米求米求米求米看面经啦 大感谢! |