# Payment System

The Merso BNPL payment system enables users to purchase NFTs with flexible payment plans while maintaining full functionality in games.

You can watch [this video](https://merso.io/wp-content/uploads/2023/10/cities.mp4) to see how it works.

The video demonstrates the process where the game signs transactions, meaning the wallets are managed internally by the game and not through an external provider like Metamask.

* **First Click (on the city):** This is the initial call where data related to the loan being requested is returned.
* **Second Click (purchase):** This involves the second and third calls, which include balance authorization and the loan request/payment.
  * During the second call, both signatures with our smart contracts are managed by the developer through integrated wallets, which is why no popups appear.

## 🎯 Payment Overview

The BNPL system operates on a **50% upfront, 4-week payment plan** structure where users pay half the NFT price immediately and the remaining balance over four weekly installments.

**Step 1: NFT Selection**

When a user decides to purchase an NFT using BNPL, they initiate the process by selecting the BNPL option in their game's marketplace. The user sees both regular purchase and BNPL options, allowing them to choose the payment method that best suits their needs.

**Step 2: Upfront Payment**

The user pays 50% of the NFT price upfront, which is transferred directly to the MersoBNPL smart contract. This upfront payment serves as the user's initial commitment to the purchase and demonstrates their intent to complete the transaction.

**Step 3: Protocol Payment to Game**

Once the user's 50% payment is received, the protocol immediately pays the full NFT price to the game company using tokens from the MersoTokenPool. This ensures the game company receives their full revenue upfront, eliminating any payment risk on their end.

**Step 4: NFT Transfer to Protocol**

The original NFT is transferred from the game company to the MersoBNPL contract, where it remains as collateral during the payment period. This transfer secures the NFT for the protocol while the user completes their payments.

**Step 5: WrappedNFT Creation**

A WrappedNFT is created and minted to the user's wallet. This WrappedNFT is a 1:1 copy of the original NFT with identical metadata, appearance, and functionality, allowing users to use it seamlessly in their games as if it were the original NFT.

**Step 6: Weekly Payment Processing**

The remaining 50% of the NFT price is divided into four equal weekly payments of 12.5% each. These payments are processed automatically by the protocol at 7-day intervals, with no action required from the user. The protocol handles all transaction costs, including gas fees.

**Step 7: Payment Completion**

Upon successful completion of all four weekly payments, the protocol transfers the original NFT to the user's wallet and burns the WrappedNFT, completing the BNPL transaction. This final step ensures users receive full ownership of their purchased NFT.

## 💰 Payment Flow

```
┌─────────────────────────────────────────────────────────────────┐
│                    PAYMENT FLOW                                 │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  1. User selects NFT in game marketplace                        │
│     ┌─────────────────┐                                         │
│     │   Game UI       │                                         │
│     └─────────────────┘                                         │
│              │                                                  │
│              ▼                                                  │ 
│  2. User pays 50% upfront                                       │
│     ┌─────────────────┐        ┌─────────────────┐              │              
│     │   User Wallet   │──50%──►│   Token Pool    │              │
│     └─────────────────┘        └─────────────────┘              │
│              │                                                  │
│              ▼                                                  │
│  3. MersoBNPL pays remaining %                                  │
│     ┌─────────────────┐        ┌─────────────────┐              │
│     │   TokenPool     │──X%───►│   Game Company  │              │
│     └─────────────────┘        └─────────────────┘              │
│              │                                                  │
│              ▼                                                  │
│  4. NFT transferred to MersoBNPL                                │
│     ┌─────────────────┐        ┌─────────────────┐              │         
│     │   Game NFT      │───────►│   MersoBNPL     │              │
│     └─────────────────┘        └─────────────────┘              │
│              │                                                  │
│              ▼                                                  │
│  5. WrappedNFT created and sent to user                         │
│     ┌─────────────────┐        ┌─────────────────┐              │              
│     │   WrappedNFT    │───────►│   User Wallet   │              │
│     └─────────────────┘        └─────────────────┘              │
│              │                                                  │
│              ▼                                                  │
│  6. Weekly payments begin                                       │
│     ┌─────────────────┐           ┌─────────────────┐           │              
│     │   User Wallet   │──Weekly──►│   MersoBNPL     │           │
│     └─────────────────┘           └─────────────────┘           │
│              │                                                  │
│              ▼                                                  │
│  7. Payment completion                                          │
│     ┌─────────────────┐        ┌─────────────────┐              │
│     │   Original NFT  │───────►│   User Wallet   │              │
│     └─────────────────┘        └─────────────────┘              │
│     ┌─────────────────┐        ┌─────────────────┐              │
│     │   WrappedNFT    │───────►│   Burned        │              │
│     └─────────────────┘        └─────────────────┘              │
└─────────────────────────────────────────────────────────────────┘
```

## 📋 Payment Structure

### **Payment Breakdown**

```javascript
// Payment structure example
const paymentStructure = {
  nftPrice: "1.0 ETH",
  upfrontPayment: "0.5 ETH (50%)",
  remainingBalance: "0.5 ETH (50%)",
  weeklyPayment: "0.125 ETH (12.5% per week)",
  totalPayments: 4,
  paymentInterval: "7 days"
};
```

### **Payment Schedule**

| Week | Payment Amount | Cumulative Paid | Remaining Balance |
| ---- | -------------- | --------------- | ----------------- |
| 0    | 50% upfront    | 50%             | 50%               |
| 1    | 12.5%          | 62.5%           | 37.5%             |
| 2    | 12.5%          | 75%             | 25%               |
| 3    | 12.5%          | 87.5%           | 12.5%             |
| 4    | 12.5%          | 100%            | 0%                |

## 🚨 Default Handling

If a user fails to maintain sufficient balance for a weekly payment, the protocol implements a 5-try system with daily attempts. Each failed attempt triggers an email notification to the user. If after 5 attempts the user still hasn't provided sufficient funds, the protocol executes a default, burning the WrappedNFT and retaining the original NFT as compensation.

The entire payment flow is designed to be user-friendly and automated, requiring minimal user intervention while providing comprehensive communication throughout the process. This approach maximizes user adoption while ensuring the protocol's financial sustainability through clear default handling and risk management.

### **Payment Failure Process**

If users don't pay their weekly portion, the protocol implements a **5-try system**:

### Timeline

| Day | Action                 | User Communication                               |
| --- | ---------------------- | ------------------------------------------------ |
| 1   | First payment attempt  | Email notification                               |
| 2   | Second payment attempt | Email notification                               |
| 3   | Third payment attempt  | Email notification                               |
| 4   | Fourth payment attempt | Email notification                               |
| 5   | Fifth payment attempt  | Final email notification                         |
| 6   | Default execution      | WrappedNFT burned, original NFT kept by protocol |

## 💡 Key Benefits

### **For Users**

* **Flexible Payments**: Pay 50% upfront, rest over 4 weeks
* **No Gas Fees**: Protocol handles all transaction costs
* **Seamless Gaming**: WrappedNFT works exactly like original NFT
* **Automatic Processing**: No manual payment actions required
* **Clear Communication**: Email notifications for all payment events

### **For Game Companies**

* **Immediate Revenue**: Receive full NFT price upfront
* **No Payment Risk**: Protocol assumes all payment risk
* **Seamless Integration**: WrappedNFTs work identically to originals
* **User Retention**: BNPL increases user purchasing power
* **Analytics**: Comprehensive payment performance insights

### **For Protocol**

* **Risk Management**: 5-try default system with clear timeline
* **Revenue Generation**: Difference between user payment and game payment
* **Automated Processing**: No manual intervention required
* **Clear Communication**: Email system keeps users informed
