如何使用Stripe Library退款给客户

时间:2015-08-08 21:24:08

标签: stripe-payments

我正在使用Stripe来处理付款流程,而且当我必须退还客户时,我才会这样做。

到目前为止,我正在使用此代码:

        $customer = \Stripe\Customer::create(array(
                "source" => $token,
                "description" => $email)
        );

        $charge = \Stripe\Charge::create(array(
            'amount' => $amount, // Amount in cents!
            'currency' => $this->currency,
            "description" => $email,
            "customer" => $customer->id
        ));

完成此操作后,我将客户ID存储到我的用户表客户。我有客户存储的ID,后来我想退还给他,我该怎么做?

我知道您可以使用以下代码退款:

    $charge = \Stripe\Charge::retrieve($charge_id);
    $refund = $charge->refunds->create();

我的情况有点不同,我如何在某种程度上使用客户ID找到charge_id?

由于

1 个答案:

答案 0 :(得分:0)

sidemenu.controller('profileCtrl', ['$scope', '$rootScope', '$location', '$http', 
    'allServices', '$document', 'PropertyDetails', '$routeParams', '$window', '$location', 
    '$anchorScroll', 'customVariables','$mdDialog','raisedEnquiryDetails','$anchorScroll', function(a, b, c, d, e, f, h, r, w, l, s, cust,v,rse,scrl) {

 e.getProjectwishlist().then(function(result) {
           alert(JSON.stringify(result));
        }, function(error) {
            alert("error");
        });




var srchCls_Element = angular.element(document.querySelector('.navbar-affixed-top'));

        if (srchCls_Element) {
            srchCls_Element.addClass('listing-navbar');
        }

a.$on('$routeChangeStart', function(scope, next, current) {
            b.homepage = true;
            b.filter = false;
            b.innerHeader = "";
            b.searchFilter = false;
          srchCls_Element.removeClass('listing-navbar');

        });



    a.homeloan=function(){
        c.path('/quicklinks/homeloan');

        }

    a.docHome=function(){
         c.path('/quicklinks/docHome');

        }

}]);

然后添加以下行:

$charge = \Stripe\Charge::create(array(
            'amount' => $amount, // Amount in cents!
            'currency' => $this->currency,
            "description" => $email,
            "customer" => $customer->id
));

现在你得到$ result变量的所有结果,然后你会发现:

$details = json_decode($charge);
$result = get_object_vars($details);