使用Dwolla的API发送资金并使用PHP来完成它?

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了使用Dwolla的API发送资金并使用PHP来完成它?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
大家好,我又回来了,在我上一篇文章中,我试图使用SOAP api( Integrating Dwolla with PHP with their API),但我发现SOAP API已被弃用,显然Dwolla有更高效的方式,如REST / oAuth2.0这就是为什么我今天在这里询问如何使用其余的API已经差不多2周了,我真的想学习这个.

首先,我会说我已经成功获得了access_token,我没有遇到任何问题.问题在于,当我尝试使用发送端点(https://www.dwolla.com/developers/endpoints/accountapi/send)时,基本上都是在尝试汇款和帐户.我的确切问题是我永远无法得到成功的回应;仅错误错误消息响应.

因此,在索引页面上,我有“为您的帐户添加资金链接.用户将点击该链接,它将带他们到Dwolla页面接受他们登录他们的Dwolla帐户然后接受网站要求的权限.在用户按下“接受”后,它将重定向到我选择的所选URL,并发送回access_token以用于授权目的.这是我的代码(这是Dwolla重定向页面,也发送了access_token)

<?PHP
//define VARiables
    $key            = 'redacted';
    $secret         = 'redacted';
    $dwolla_client_id   = urlencode($key);
    $dwolla_secret_key  = urlencode($secret);
$code = urlencode($_GET["code"]);
//get token
    $retireve_token = file_get_contents("https://www.dwolla.COM/oauth/v2/token?client_id=".$dwolla_client_id."&amp;client_secret=".$dwolla_secret_key."&grant_tyPE=authorization_code&redirect_uri=http://localhost/purchase_order.PHP&code=".$code);


    $decoded_JSON = json_decode($retireve_token,true);


        var_dump($decoded_json);
        if($decoded_json["access_token"]){
                    $arr = '{
                            "oauth_token": "'.$decoded_json["access_token"].'","fundsSource": "balance","pin": "1111","notes": "Payment for services rendered","amount": 1.01,"destinationId": "812-111-1111","assumeCosts": false,"facilITatorAmount": 0,"destinationType": "dwolla"
                    }';
                    $opts = array('http'=>array('method'=>"POST",'content'=> $arr,'header' => 'Content-type: application/json'));

                    $ctx = stream_context_create($opts);
            $send_request = file_get_contents('https://www.dwolla.com/oauth/rest/accountapi/send',false,$ctx);

            var_dump(json_decode($send_request));
        }

?>

我收到这样的消息,例如

你想要做的是获取请求,而Dwolla文档将此称为post请求.

你可以做的更好的是用他们的PHP库与内置的方法打电话.这是一个用于进行休息调用的标准库,比编写上面代码片段中编写的方式要好得多.

https://github.com/Dwolla/dwolla-php

脚本宝典总结

以上是脚本宝典为你收集整理的使用Dwolla的API发送资金并使用PHP来完成它?全部内容,希望文章能够帮你解决使用Dwolla的API发送资金并使用PHP来完成它?所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。