zoukankan      html  css  js  c++  java
  • 支付宝退款流程

    当交易发生之后一段时间内,由于买家或者卖家的原因需要退款时,卖家可以通过退款接口将支付款退还给买家,支付宝将在收到退款请求并且验证成功之后,按照退款规则将支付款按原路退到买家帐号上。 交易超过约定时间(签约时设置的可退款时间)的订单无法进行退款 支付宝退款支持单笔交易分多次退款,多次退款需要提交原支付订单的商户订单号和设置不同的退款单号。一笔退款失败后重新提交,要采用原来的退款单号。总退款金额不能超过用户实际支付金额

    官方文档:https://docs.open.alipay.com/api_1/alipay.trade.refund

    参考代码:

    from alipay import AliPay
    from urllib2 import  urlopen
    import os
    class AliPayNew(AliPay):
        def api_alipay_trade_refund(self, refund_amount, out_trade_no=None, trade_no=None, **kwargs):#原方法存故障,重写该方法
            biz_content = {
                "refund_amount": refund_amount
            }
            biz_content.update(**kwargs)
            if out_trade_no:
                biz_content["out_trade_no"] = out_trade_no
            if trade_no:
                biz_content["trade_no"] = trade_no
            data = self.build_body("alipay.trade.refund", biz_content)
            url = self._gateway + "?" + self.sign_data(data)
            raw_string = urlopen(url, timeout=15).read().decode("utf-8")
            return raw_string
    
    
    ssh_keys_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "ssh_keys")
    app_private_key_path = os.path.join(ssh_keys_path, "app_private_key.pem") #指定证书路径
    alipay_public_key_path = os.path.join(ssh_keys_path, "app_public_key.pem")
    
    appid = "AliPayAPPID"
    alipay = AliPayNew(appid=appid, app_private_key_path = app_private_key_path,
                    alipay_public_key_path = alipay_public_key_path, sign_type = 'RSA2',
                    app_notify_url = None) 
    
    notify_url = "http://{0}/app/alipayrefund/callback" #回调函数URL
    order_string = alipay.api_alipay_trade_refund(
        out_trade_no="out_trade_no",
        refund_amount="refund_amount",
        notify_url=notify_url
    )
    print order_string #打印结果
    
    #上面的相关参数可以支付宝开发文档找到,填写相应参数即可
    

     

  • 相关阅读:
    [Web Security] Create a hash salt password which can stored in DB
    [Angular] Stagger animation v4.3.3
    [D3] Make D3 v4 Charts Responsive with the viewBox attribute
    [D3] Create Chart Axes with D3 v4
    [D3] Margin Convention with D3 v4
    [D3] Better Code Organization with selection.call() with D3 v4
    [D3] Basic Interactivity with D3 v4
    [Angular] Reactive Store and AngularFire Observables
    Google Play和基于Feature的过滤
    Three Swaps DFS
  • 原文地址:https://www.cnblogs.com/wjohh/p/10792901.html
Copyright © 2011-2022 走看看