【发布时间】:2021-03-18 11:34:31
【问题描述】:
我目前正在使用定期 PayPal 付款。我不确定第一次付款何时完成。就我而言,我希望在用户订阅时完成第一笔付款,并在 1 个月后自动续订。
这是我的 RestAPI 代码。
<?php
namespace App\Http\Controllers\WSController;
use App\Http\Controllers\Controller;
use App\Models\PaymentPlans;
use App\Models\Subscription;
use App\Models\Users;
use Auth;
use DB;
use Hash;
use Session;
use Stripe;
use Illuminate\Http\Request;
use Twilio\Rest\Client;
class WSPaypalTestController extends Controller
{
public function paypalpaymenttest()
{
global $environment;
$paymentAmount = urlencode('105.87');
$currencyID = urlencode('USD');
$paymentType = urlencode('Authorization');
$returnURL = "http://localhost/paypal/new/success.php";
$cancelURL = 'http://localhost/paypal/new/cencel.php';
$paypal_data = [
'PAYMENTREQUEST_0_CURRENCYCODE' => $currencyID,
'PAYMENTREQUEST_0_PAYMENTACTION' => 'SALE',
'PAYMENTREQUEST_0_DESC' => 'Hosted Saas Tier 1 and Community Management Services',
'PAYMENTACTION' => $paymentType,
'L_BILLINGTYPE0' => 'RecurringPayments',
'L_BILLINGAGREEMENTDESCRIPTION0' => 'Description of Community Management Services',
'L_PAYMENTREQUEST_0_NAME0' => 'Community Management Services 8 hours for $0.01',
'L_PAYMENTREQUEST_0_NUMBER0' => '010101',
'L_PAYMENTREQUEST_0_QTY0' => '1',
'L_PAYMENTREQUEST_0_AMT0' => $paymentAmount,
'PAYMENTREQUEST_0_ITEMAMT' => $paymentAmount,
'PAYMENTREQUEST_0_AMT' => $paymentAmount
];
$nvpStr = http_build_query($paypal_data);
$methodName_ = 'doExpressChechoutPayment';
$API_UserName = urlencode('');
$API_Password = urlencode('');
$API_Signature = urlencode('');
$API_Endpoint = "https://api-3t.paypal.com/nvp";
if ("sandbox" === $environment || "beta-sandbox" === $environment) {
$API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
}
$version = urlencode('124.0');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$nvpreq="METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature&$nvpStr";
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
$httpResponse =curl_exec($ch);
if (!$httpResponse) {
exit("$methodName_ failed:".curl_error($ch).'('.curl_errno($ch).')');
}
$httpResponseAr = explode("&", $httpResponse);
$httpParsedResponseAr = array();
foreach ($httpResponseAr as $i => $value) {
$tmpAr = explode("=", $value);
if (sizeof($tmpAr) > 1) {
$httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
}
}
if ((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
}
}
【问题讨论】:
-
我没有任何问题,但是如果您使用的是使用面向对象概念的 laravel,为什么不使用面向对象的 guzzle 而不是 curl
标签: php laravel paypal payment