# OmniPay

Omnify's payment suite and infrastructure is all hosted in OmniPay. It paves the way for full payments, receipts, refunds, installments, and instant revenue withdrawals. Accessible from [pay.omnify.finance](http://pay.omnify.finance/) and [app.omnify.finance/payments](https://app.omnify.finance/payments).

<figure><img src="/files/KCyunjU78qg9iGU8NDSl" alt=""><figcaption><p>OmniPay Logo</p></figcaption></figure>

In this section we will cover making payments, paying installments, withdrawing revenues, and checking if a payment was made and if a payment was refunded. Payments are made in the native token of the network you are on. You can find a list of all Omnify services' tiers and fees at [omnify.finance/fees](https://omnify.finance/fees).&#x20;

Start by downloading the [OmniPay interface](https://github.com/OmniKobra/Omnify/blob/main/Omni/Contracts/Omnify/src/interfaces/paymentsInterface.sol) found in our github repo.

### Making a payment

```solidity
function makePayment(
    string memory _id, // payment ID, must not be a duplicate
    uint256 _amount, // amount due in wei
    address _vendor, // vendor address
    bool _isInstallments, // true if payment is a downpayment with installments
    uint256 _fullAmount, // if is installments place the full amount due here, use _amount if full payment (in wei)
    uint8 _installmentPeriod // how many months the installment period is max is 120
) external payable;
```

{% stepper %}
{% step %}

### Define OmniPay variable

```solidity
IPayments99 public omnipay = IPayments99(0xEe47e2484342eA7Bcf13B9e6d4F9d53B28F1b724); // address on Avalanche C-Chain
```

{% endstep %}

{% step %}

### Get Omnify's fee / payment

```solidity
uint256 public feePerPayment = omnipay.feePerPayment();
```

{% endstep %}

{% step %}

### Call `makePayment`&#x20;

<pre class="language-solidity"><code class="lang-solidity"><strong>uint256 public _amount = 1 * 10 ** 15;
</strong><strong>omnipay.makePayment{value: feePerPayment + _amount}(
</strong>'ID1', // payment ID, must not be a duplicate
_amount, // amount due in wei
address(0x6BF6D002b5140b7CE0A0a4993621ecE52271e5f0), // vendor address
false, // true if payment is a downpayment with installments
_amount, // if is installments place the full amount due here, if not use _amount (in wei)
0 // how many months the installment period is max is 120
);
</code></pre>

{% endstep %}
{% endstepper %}

### Checking if a payment was made or refunded via ID

We lookup a payment by its ID from the OmniPay contract by calling `lookupPayment`. The return value is a `Payment` struct containing all details about the payment.

```solidity
struct Payment {
    string id; // payment ID
    uint256 amount; // amount due in Wei
    address customer; // customer address
    address vendor; //  vendor address
    bool isPaid; // true if the payment exists and has been paid
    bool isRefunded; // true if the payment was refunded
    bool isInstallments; // true if the payment contains installments
    uint256 fullAmount; // the full amount of the payment
    uint256 amountPerInstallment; // amount due per month 
    uint8 installmentPeriod; // the installment period in months
    uint8 paidInstallments; // how many installments have been paid 
    uint8 remainingInstallments; // how many installments remain
    uint256 datePaid; // date the payment was made
    uint256 dateLastInstallmentPaid; // date the last installment was paid
}
```

```solidity
IPayments99 public omnipay = IPayments99(0xEe47e2484342eA7Bcf13B9e6d4F9d53B28F1b724);
IPayments99.Payment public payment = omnipay.lookupPayment('ID1'); 
bool public isPaid = payment.isPaid == true; // check if paid
bool public isRefunded = payment.isRefunded == true; // check if refunded
```

### Paying installments

When paying an installment be sure to get the amount per installment of that payment, and the fee Omnify charges per installment.&#x20;

```solidity
IPayments99 public omnipay = IPayments99(0xEe47e2484342eA7Bcf13B9e6d4F9d53B28F1b724);
IPayments99.Payment public payment = omnipay.lookupPayment('ID1');
uint256 public feePerInstallment = omnipay.feePerInstallment();
uint256 public amountPerInstallment = payment.amountPerInstallment;
omnipay.payInstallment{value: amountPerInstallment + feePerInstallment}('ID1');
```

Additionally, if its the last installment it is required to calculate the final installment by subtracting the paid amount so far from the full amount. Replace `amountPerInstallment` with `paidSoFar` and `installmentAmount` .

```solidity
IPayments99 public omnipay = IPayments99(0xEe47e2484342eA7Bcf13B9e6d4F9d53B28F1b724);
IPayments99.Payment public payment = omnipay.lookupPayment('ID1');
uint256 public feePerInstallment = omnipay.feePerInstallment();
uint256 public paidSoFar = payment.paidInstallments * payment.amountPerInstallment;
uint256 public installmentAmount = payment.fullAmount - paidSoFar;
omnipay.payInstallment{value: installmentAmount + feePerInstallment}('ID1');
```

### Withdrawing Revenues

Any vendor can withdraw any amount of their revenues whenever they wish by simply calling `withdrawBalance` , granted they've received payments equal or more than the amount they are trying to withdraw.

```solidity
IPayments99 public omnipay = IPayments99(0xEe47e2484342eA7Bcf13B9e6d4F9d53B28F1b724);
omnipay.withdrawBalance(1 * 10 ** 15);
```

***All our crypto payment needs are covered with OmniPay.*****♾️**


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://omnify.gitbook.io/omnify-docs/deep-dive/omnipay.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
