#stripe #payment #customer #synchronous #list #processing #charge

payup

一个用于处理rust + stripe支付的同步 + 异步支付库

8次发布

0.1.45 2022年6月25日
0.1.44 2022年1月28日
0.1.0 2021年10月26日

财务类别中排名68

每月下载22

MIT/Apache

180KB
3K SLoC

Payup

描述

一个用于处理rust + stripe支付的同步 + 异步支付库。

我因为缺乏同步支付库而构建了这个库。目前我只关注另一个项目需要的特性。

当前Stripe特性

  • 余额

    • 能够获取您的stripe账户的账户余额
  • 余额交易

    • 能够检索一个余额交易
    • 能够列出所有余额交易
    • 能够将卡附加到支付方式上
  • 收费

    • 能够检索一个收费
    • 能够列出所有收费
    • 能够更新现有的收费
    • 能够创建新的收费
    • 能够捕捉收费
  • 客户

    • 能够检索一个客户
    • 能够列出所有客户
    • 能够更新现有的客户
    • 能够创建新的客户
    • 能够销毁客户
    • 能够将支付方式附加到客户上
    • 能够列出客户的发票
    • 能够列出客户的支付方式
  • 争议

    • 能够检索一个争议
    • 能够列出所有争议
    • 能够关闭争议
    • 能够更新现有的争议
  • 事件

    • 能够检索一个事件
    • 能够列出所有事件
  • 文件

    • 能够检索一个文件
    • 能够列出所有文件
    • 能够创建一个文件
  • 文件链接

    • 能够检索一个文件链接
    • 能够列出所有文件链接
    • 能够创建一个文件链接
    • 能够更新现有的文件链接
  • 发票

    • 能够检索一个发票
    • 能够列出所有发票
    • 能够创建一个发票
    • 能够更新现有的发票
  • 授权

    • 能够检索一个授权
  • 支付方式

    • 能够检索一个支付方式
    • 能够创建一个新的支付方式
  • 计划

    • 能够检索一个计划
    • 能够列出所有计划
    • 能够更新现有的计划
    • 能够创建一个新的计划
  • 价格

    • 能够创建一个新的价格
  • 订阅

    • 能够创建一个新的订阅
    • 能够检索一个订阅
    • 能够更新现有的订阅
    • 能够取消订阅

路线图

  • 0.1.0:准Stripe支持
  • 0.2.0: 完全支持 Stripe API
  • 0.3.0: 支持Paypal
  • 0.4.0: 支持加密货币

如何使用库

将以下行添加到您的 cargo.toml 中

payup = "0.1.45"

示例

extern crate payup;

fn main() {

    // Client and Secret for Stripe account
    // In a production environment...load values from environment variables.
    let client = format!("sk_test_");
    let secret = format!("");

    // Create the Authentication refererence
    let auth = payup::stripe::Auth::new(client, secret);

    let get_subscription = payup::stripe::Subscription::get(auth.clone(), "sub_1JpgYvGrEH09RU9ueB31tuQp".to_string());
    match get_subscription {
        Ok(sub) => {
            println!("SUBSCRIPTION_GET: {:?}", sub);
        },
        Err(err) => println!("{}", err),
    }


    let get_all_invoices = payup::stripe::Invoice::list(auth.clone(), None, None);
    match get_all_invoices {
        Ok(sub) => {
            println!("ALL_INVOICES: {:?}", sub);
        },
        Err(err) => println!("{}", err),
    }

    let get_one_invoice = payup::stripe::Invoice::get(auth.clone(), "in_1KM0TcGrEH09RU9uKzfi8E4x".to_string());
    match get_one_invoice {
        Ok(sub) => {
            println!("SINGLE_INVOICE_GET: {:?}", sub);
        },
        Err(err) => println!("{}", err),
    }


    // Build a customer object
    let mut cust = payup::stripe::Customer::new();
    cust.name = Some("Rust Test".to_string());
    cust.description = Some("A test customer from rust.".to_string());
    cust.phone = Some("333-333-3333".to_string());
    cust.email = Some("[email protected]".to_string());
    cust.payment_method = None;
    
    // Post customer to stripe and update the local cust variable
    let cust = cust.post(auth.clone()).unwrap();

    let cust_id = cust.id.clone().unwrap();


    let get_cust = payup::stripe::Customer::get(auth.clone(), cust_id.clone());
    match get_cust {
        Ok(sub) => {
            println!("CUST_GET: {:?}", sub.clone());


  



        },
        Err(err) => println!("{}", err),
    }


    // Fetch customers from stripe account
    let customers = payup::stripe::Customer::list(auth.clone()).unwrap();
    // println!("customers: {:?}", customers);

    // Create a new plan
    let mut np = payup::stripe::Plan::new();
    np.amount = Some("200".to_string());
    np.currency = Some("usd".to_string());
    np.interval = Some("month".to_string());
    np.product = Some("prod_KSywTYVmG9jVC4".to_string());
    let new_plan = np.post(auth.clone()).unwrap();

    // Fetch plans from stripe account
    let plans = payup::stripe::Plan::list(auth.clone());
    // println!("plans: {:?}", plans);

    // Create a new card
    let mut card = payup::stripe::Card::new();
    card.number = Some(format!("4242424242424242"));
    card.exp_month = Some(format!("01"));
    card.exp_year = Some(format!("2023"));
    card.cvc = Some(format!("314"));

    // Create a payment method from the card
    let mut payment_method = payup::stripe::PaymentMethod::new();
    payment_method.method_type = Some(format!("card"));
    payment_method.card = Some(card);
    payment_method = payment_method.post(auth.clone()).unwrap();
    println!("payment_method: {:?}", payment_method.clone());


    let payment_method_id = payment_method.id.clone().unwrap();


    let get_payment_method = payup::stripe::PaymentMethod::get(auth.clone(), payment_method_id.clone());
    match get_payment_method {
        Ok(sub) => {
            println!("PAYMENT_METHOD_GET: {:?}", sub);
        },
        Err(err) => println!("{}", err),
    }


    // Attach the payment method to the customer created earlier
    let attached = payment_method.attach(cust.clone(), auth.clone());
    
    // Did the attach work?
    match attached {
        Ok(is_attached) => {
            println!("{}", is_attached);
            if is_attached {
                println!("Payment Method ({}) is now attached to Customer ({})", payment_method_id.clone(), cust_id.clone());
            

                let mut price_items: Vec<String> = Vec::new();
                price_items.push(format!("price_1Jp6siGrEH09RU9u95Xp7soZ"));

                // Subscript the customer to the new_plan.id....
                let mut subscription = payup::stripe::Subscription::new();
                subscription.customer = Some(cust_id.clone());
                subscription.default_payment_method = Some(payment_method_id.clone());
                subscription.price_items = Some(price_items);
                subscription = subscription.post(auth.clone()).unwrap();
            
                println!("subscription: {:?}", subscription.clone());


                let get_subscription = payup::stripe::Subscription::get(auth.clone(), subscription.clone().id.unwrap());
                match get_subscription {
                    Ok(sub) => {
                        println!("SUBSCRIPTION_GET: {:?}", sub);
                    },
                    Err(err) => println!("{}", err),
                }



                let get_payment_methods = payup::stripe::Customer::payment_methods(auth.clone(), cust_id.clone(), format!("card"));
         
    

                let get_invoices = payup::stripe::Customer::invoices(auth.clone(), cust_id.clone());
                println!("CUSTOMER_INVOICES: {:?}", get_invoices);
           

                // Create a new card
                let mut new_card = payup::stripe::Card::new();
                new_card.number = Some(format!("4242424242424242"));
                new_card.exp_month = Some(format!("01"));
                new_card.exp_year = Some(format!("2023"));
                new_card.cvc = Some(format!("314"));


                // Change Payment Method
                let mut new_payment_method = payup::stripe::PaymentMethod::new();
                new_payment_method.method_type = Some(format!("card"));
                new_payment_method.card = Some(new_card);
                new_payment_method = new_payment_method.post(auth.clone()).unwrap();
                println!("new_payment_method: {:?}", new_payment_method.clone());
            
                let new_payment_method_id = payment_method.id.clone().unwrap();
                

                let mut new_subscription = payup::stripe::Subscription::new();
                new_subscription.default_payment_method = Some(new_payment_method_id);
                new_subscription.id = subscription.clone().id;
                let nnew_subscription = new_subscription.update(auth.clone());
                println!("new_subscription: {:?}", nnew_subscription);


                let subscription_cancel = payup::stripe::Subscription::cancel(auth.clone(), format!("sub_1JpgYvGrEH09RU9ueB31tuQp")).unwrap();
                println!("subscription_cancel: {:?}", subscription_cancel);


            }
        },
        Err(err) => println!("fail: {}", err)
    }




}

许可协议

基于 Apache 2.0 协议发布。

通过以下方式支持并关注我的工作:

购买我的酷炫 NTFs

查看我的 Github

关注我的 Facebook 页面

订阅我的 Patreon

或者捐赠加密货币

  • ADA: addr1qyp299a45tgvveh83tcxlf7ds3yaeh969yt3v882lvxfkkv4e0f46qvr4wzj8ty5c05jyffzq8a9pfwz9dl6m0raac7s4rac48
  • ALGO: VQ5EK4GA3IUTGSPNGV64UANBUVFAIVBXVL5UUCNZSDH544XIMF7BAHEDM4
  • ATOM: cosmos1wm7lummcealk0fxn3x9tm8hg7xsyuz06ul5fw9
  • BTC: bc1qh5p3rff4vxnv23vg0hw8pf3gmz3qgc029cekxz
  • ETH: 0x7A66beaebF7D0d17598d37525e63f524CfD23452
  • ERC20: 0x7A66beaebF7D0d17598d37525e63f524CfD23452
  • XLM: GCJAUMCO2L7PTYMXELQ6GHBTF25MCQKEBNSND2C4QMUPTSVCPEN3LCOG
  • XTZ: tz1SgJppPn56whprsDDGcqR4fxqCr2PXvg1R

依赖项

~9–24MB
~380K SLoC