使用 PHP 中的 PayPal API 直接将资金从一个个人帐户转移到另一个帐户
Posted
技术标签:
【中文标题】使用 PHP 中的 PayPal API 直接将资金从一个个人帐户转移到另一个帐户【英文标题】:Transfer funds from one personal account to another directly with PayPal API in PHP 【发布时间】:2021-08-04 04:09:09 【问题描述】:我想知道在 php 中将资金从一个人转移到另一个人的最佳选择是什么。 之前有一些解决方案,但现在已弃用,例如 Adaptive API 等。 我在here 找到了一个解决方案,但是当我转移资金时,它会发送到我的默认企业帐户。 代码如下:
$params = [
'intent' => 'CAPTURE',
'purchase_units' => [
[
'amount' => [
'currency_code' => $currency,
'value' => (string) $amount
],
'payee' => [
'email_address' => $address //receiver user PayPal email address
]
]
]
];
$data = $this->encodeData($params);
$headers = $this->getAuthHeaders($data);
$res = $this->execute('POST, '/v2/checkout/orders', $data, $headers);
真的很奇怪为什么我不能直接发送给这个收件人。
【问题讨论】:
嗯,乍一看实际上看起来是正确的。您能否在设置$data
和$res
后立即转储它们的运行时日志,以便我们可以看到哪里出了问题?
"id":"1U6354702F236135S","status":"CREATED","links":["href":"https:\/\/api.sandbox.paypal.com\ /v2\/checkout\/orders\/1U6354702F236135S","rel":"self","method":"GET","href":"https:\/\/www.sandbox.paypal.com\ /checkoutnow?token=1U6354702F236135S","rel":"approve","method":"GET","href":"https:\/\/api.sandbox.paypal.com\/v2\/checkout \/orders\/1U6354702F236135S","rel":"update","method":"PATCH","href":"https:\/\/api.sandbox.paypal.com\/v2\/checkout \/orders\/1U6354702F236135S\/capture","rel":"capture","method":"POST"] :这里是$res
DATA====>"intent":"CAPTURE","purchase_units":["amount":"currency_code":"USD","value":"50" ,"收款人":"email":"sb-13431550910@personal.example.com"],"application_context":"user_action":"PAY_NOW","shipping_preference":"NO_SHIPPING","return_url": "https:\/\/xxx.com","cancel_url":"https:\/\/xxx.com" : 这里是 $data
但在批准后payee
地址更改为我的主要凭据所有者帐户:..."status":"APPROVED","purchase_units":["reference_id":"default", "amount":"currency_code":"USD","value":"50.00","payee":"email_address":"htag@bodproductions.com"...],"payer":"name ":"given_name":"John","surname":"Doe","email_address":"sb-ksyxz5947819@personal.example.com","payer_id":"96Z48PGVR3WRE","address":" country_code":"US"....]
【参考方案1】:
DATA====>"intent":"CAPTURE","purchase_units":["amount":"currency_code":"USD","value":"50","payee": "email":"sb-13431550910@personal.example.com"],"application_context":"user_action":"PAY_NOW","shipping_preference":"NO_SHIPPING","return_url":"https:// xxx.com","cancel_url":"https://xxx.com" : 这里是 $data
您的请求数据指定了email
而不是email_address
,因此无法识别并被忽略。
检查您的 encodeData 函数,了解发生这种情况的原因。
【讨论】:
交易完成后,再用capture api查看状态,会报错吗? "name":"INVALID_RESOURCE_ID","message":"未找到请求的资源 ID","debug_id":"ffbbcd8fe8042","information_link":"https:\/\/developer.paypal.com\/docs \/api\/payments.payouts-batch\/#errors","details":[],"links":[] v1/payments/payouts 与上述任何一项都不相关,也许您正在寻找 v2/payments/captures,developer.paypal.com/docs/api/payments/v2/#captures_get 但是,由于接收方账户与您不同,您可能无权通过交易ID获取。以上是关于使用 PHP 中的 PayPal API 直接将资金从一个个人帐户转移到另一个帐户的主要内容,如果未能解决你的问题,请参考以下文章
使用 Paypal Rest API 的直接卡支付时如何安全地获取客户的信用卡
PHP 支付中的 Paypal API Express Checkout 错误代码 13113