This is not an endpoint, but a way to retrieve the next payment due on a plan, and make a payment.
For the best experience, please refer to the SDK documentation. You'll be able to install our library and get started in not only retrieving the next payment on plans but also interacting with the Cyan Protocol.
In order to retrieve the next payment data, use the getNextPayment
function from the smart contract which uses returned data from the Retrieve Plan data, or from the Retrieve user's Activated, Funded and Pending Plans data.
getNextPayment
function accepts following inputs:
Fields | Description |
---|---|
address | Cyan Wrapper address of the collection. |
tokenId | NFT id |
This function returns the following data:
Fields | Description |
---|---|
payAmountForCollateral | Payment amount for collateral as BigNumber |
payAmountForInterest | Payment amount for interest as BigNumber |
payAmountForService | Platform Fee as BigNumber as BigNumber |
currentPayment | Payment amount to be made as BigNumber |
nextPaymentDate | Next due date of the payment |
After usinggetNextPayment
function from the smart contract and getting some of the data in the table.
We can use currentPayment
to make a payment using pay
function from the smart contract.
pay
function accepts following inputs:
Fields | Description |
---|---|
address | Cyan Wrapper address of the collection. |
tokenId | NFT id |
value | Payment amount to be made as BigNumber |
Example:
const provider = ... // your Web3 provider
const contract = new Contract( // Contract from ether.js
plan.paymentPlanContractAddress, // returned from Plan API
abi, // Cyan ABI
provider // Web3 provider
)
// Retrieve the next payment due on a plan
const [
payAmountForCollateral,
payAmountForInterest,
payAmountForService,
currentPayment,
nextPaymentDate,
] = await contract.getNextPayment(plan.wNFTContract, plan.wNFTTokenId);
// Make a payment
const res = await contract.pay(plan.wNFTContract, plan.wNFTTokenId, {
value: currentPayment
})