Git Product home page Git Product logo

recurring_hackathon's Introduction

Contract

Contract is deployed here https://stellar.expert/explorer/testnet/contract/CDHXNJXGVROYZYVGJ5Z6SW3MAJYNPBQMPB42LD76YXKWNKGOYM3OZGJP

pub struct MandateConfig{
    pub amount: i128,
    pub start : u64,
    pub last_charged: u64,
    pub charge_interval: u64,
    pub shopper: Address,
    pub merchant: Address,
    pub token_id: Address,
}

pub trait MandateContractTrait {
    fn create_mandate(env: Env, config: MandateConfig, untill: u32) -> u64;
    fn charge_mandate(env: Env, mandate_id: u64);
    fn revoke_mandate(env: Env, mandate_id: u64);
}

Create_mandate

The shopper can call create_mandate to create a subscription and give the contract permission to spend their funds. The shopper can specify a charge_interval. The subscription can be charged every charge_interval seconds.

charge_mandate

The merchant can call charge_mandate every charge_interval seconds to charge the subscription. The function checks that charge_interval time has passed since the last charge.

revoke_mandate

revoke_mandate can be called by the shopper to cancel the subscription.

Backend

The backend is a server written in kotlin that acts as a middleman between the merchant and contract, the shopper and contract.

  1. The merchant can make a POST request to /payment with the below structure to create a payment.
{
  "amount": "100000000",
  "asset": "native",
  "type": "first",
  "chargeInterval": "4s",
  "description" : "YOU NEED TO PAY"
}
  1. the server responds with something like this
{
  "paymentId": "2",
  "redirectUrl": "http://localhost:8080/confirmmandate?id=2"
}
  1. The merchant redirects the shopper to the redirectUrl.
  2. The shopper confirms and signs the subscription creation transaction you_need_to_pay
  3. The server submits the transaction and the shopper is shown a success screen.
  4. The server continiously checks if it should charge the subscription. If so It calls the charge_mandate contract function to charge the shopper for the subscription.

Run Backend

  1. clone https://github.com/rahimklaber/stellar_kt and run ./gradlew publishAllPublicationsToMavenLocalRepository. The backend uses my sdk, which is not published, so we need to install it first.
  2. Clone this repo and cd into the recurring(backend) folder. then run ./gradlew run.
  3. Config can be changed in Config.kt.

recurring_hackathon's People

Contributors

rahimklaber avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.