我有此代码
$product_info = array();
if(isset($cms['site']['url_data']['product_id'])){
$product_info = $cms['class']['product']->get($cms['site']['url_data']['product_id']);
}
if(!isset($product_info['id'])){
/*
echo 'No product info.';
exit();
*/
header_url(SITE_URL.'?subpage=user_subscription#xl_xr_page_my%20account');
}
$fee = $product_info['yearly_price_end'] / 100 * $product_info['fee'];
$yearly_price_end = $product_info['yearly_price_end'] + $fee;
$fee = ($product_info['setup_price_end'] / 100) * $product_info['fee'];
$setup_price_end = $product_info['setup_price_end'] + $fee;
if(isset($_SESSION['discountcode_amount'])){
$setup_price_end = $setup_price_end - $_SESSION['discountcode_amount'];
unset($_SESSION['discountcode_amount']);
}
$error = false;
$plan_id = '';
$approvalUrl = '';
$ReturnUrl = SITE_URL.'payment/?payment_type=paypal&payment_page=process_agreement';
$CancelUrl = SITE_URL.'payment/?payment_type=paypal&payment_page=cancel_agreement';
$now = $cms['date'];
$now->modify('+5 minutes');
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
$cms['options']['plugin_paypal_clientid'], // ClientID
$cms['options']['plugin_paypal_clientsecret'] // ClientSecret
)
);
use PayPal\Api\ChargeModel;
use PayPal\Api\Currency;
use PayPal\Api\MerchantPreferences;
use PayPal\Api\PaymentDefinition;
use PayPal\Api\Plan;
use PayPal\Api\Patch;
use PayPal\Api\PatchRequest;
use PayPal\Common\PayPalModel;
use PayPal\Api\Agreement;
use PayPal\Api\Payer;
use PayPal\Api\ShippingAddress;
// Create a new instance of Plan object
$plan = new Plan();
// # Basic Information
// Fill up the basic information that is required for the plan
$plan->setName($product_info['name'])
->setDescription($product_info['desc_text'])
->setType('fixed');
// # Payment definitions for this billing plan.
$paymentDefinition = new PaymentDefinition();
// The possible values for such setters are mentioned in the setter method documentation.
// Just open the class file. e.g. lib/PayPal/Api/PaymentDefinition.php and look for setFrequency method.
// You should be able to see the acceptable values in the comments.
$setFrequency = 'Year';
//$setFrequency = 'Day';
$paymentDefinition->setName('Regular Payments')
->setType('REGULAR')
->setFrequency($setFrequency)
->setFrequencyInterval("1")
->setCycles("999")
->setAmount(new Currency(array('value' => $yearly_price_end, 'currency' => $cms['session']['client']['currency']['iso_code'])));
// Charge Models
$chargeModel = new ChargeModel();
$chargeModel->setType('SHIPPING')
->setAmount(new Currency(array('value' => 0, 'currency' => $cms['session']['client']['currency']['iso_code'])));
$paymentDefinition->setChargeModels(array($chargeModel));
$merchantPreferences = new MerchantPreferences();
// ReturnURL and CancelURL are not required and used when creating billing agreement with payment_method as "credit_card".
// However, it is generally a good idea to set these values, in case you plan to create billing agreements which accepts "paypal" as payment_method.
// This will keep your plan compatible with both the possible scenarios on how it is being used in agreement.
$merchantPreferences->setReturnUrl($ReturnUrl)
->setCancelUrl($CancelUrl)
->setAutoBillAmount("yes")
->setInitialFailAmountAction("CONTINUE")
->setMaxFailAttempts("0")
->setSetupFee(new Currency(array('value' => $setup_price_end, 'currency' => $cms['session']['client']['currency']['iso_code'])));
$plan->setPaymentDefinitions(array($paymentDefinition));
$plan->setMerchantPreferences($merchantPreferences);
// ### Create Plan
try {
$output = $plan->create($apiContext);
} catch (Exception $ex){
die($ex);
}
echo $output->getId().'<br />';
echo $output.'<br />';
现在开始使用Paypal php sdk几天了,我的代码停止工作。 因此,我回到了基本状态,仍然遇到了该死的错误。
我正在尝试创建订阅计划,但出现以下错误: “ NotifyUrl不是完全限定的URL”
我不知道如何解决此问题,因为我未在代码中使用NotfifyUrl?
如果有人知道如何解决此问题,那可能会很好:)
谢谢
答案 0 :(得分:6)
PayPal昨晚对他们的API进行了更新,这已导致他们的SDK出现问题。 他们在响应中发回空值。
我必须强调错误不是在向PayPal发送请求,而是在处理响应。
错误报告:https://github.com/paypal/PayPal-PHP-SDK/issues/1151
拉取请求:https://github.com/paypal/PayPal-PHP-SDK/pull/1152
希望这会有所帮助,但是他们当前的SDK会引发异常。
答案 1 :(得分:6)
使用以下简单修补程序。
在厂商\ paypal \ rest-api-sdk-php \ lib \ PayPal \ Api \ MerchantPreferences.php中替换以下功能
public function setNotifyUrl($notify_url)
{
if(!empty($notify_url)){
UrlValidator::validate($notify_url, "NotifyUrl");
}
$this->notify_url = $notify_url;
return $this;
}
如果在return_url / cancel_url上遇到相同的错误,请添加上述if条件。
注意:这不是永久性的解决方案,您可以使用它直到从PayPal获得更新。
答案 2 :(得分:1)
从the GitHub repo for the PayPal PHP SDK,我看到没有为MerchantPreferences提供有效的NotifyUrl时引发了您提到的错误。我看到您正在设置CancelUrl和ReturnUrl,但没有设置NotifyUrl。您可能还需要设置该值,即:
$NotifyUrl = (some url goes here)
$obj->setNotifyUrl($NotifyUrl);
答案 3 :(得分:0)
原因 背后 它!
错误来自。
供应商\ paypal \ rest-api-sdk-php \ lib \ PayPal \ Validation \ UrlValidator.php
行。
if (filter_var($url, FILTER_VALIDATE_URL) === false) {
throw new \InvalidArgumentException("$urlName is not a fully qualified URL");
}
FILTER_VALIDATE_URL:根据此php函数。
无效的URL:“ http://cat_n.domain.net.in/”; //它包含_ UNDERSCORE。
有效网址:“ http://cat-n.domain.net.in/”;它以-破折号
分隔在这里您可以转储您的URL。 vendor \ paypal \ rest-api-sdk-php \ lib \ PayPal \ Validation \ UrlValidator.php
public static function validate($url, $urlName = null)
{
var_dump($url);
}
然后在此处检查:https://www.w3schools.com/PHP/phptryit.asp?filename=tryphp_func_validate_url
您可以在此处检查导致无效的字符。