api - Paypal Php Sdk - NotifyUrl 不是完全限定的 URL 错误

标签 api paypal sdk

我有这个代码

$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?

如果有人知道如何解决这个问题,那就太好了:)

谢谢

最佳答案

PayPal 昨晚对其 API 进行了更新,导致其 SDK 出现问题。 他们在响应中发回空值。

我必须强调错误不是在向 PayPal 发送请求时出现的,而是在处理他们的响应时出现的。

错误报告:https://github.com/paypal/PayPal-PHP-SDK/issues/1151

拉取请求:https://github.com/paypal/PayPal-PHP-SDK/pull/1152

希望这会有所帮助,但他们当前的 SDK 会抛出异常。

关于api - Paypal Php Sdk - NotifyUrl 不是完全限定的 URL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51424433/

相关文章:

Paypal 按使用付费

paypal - 从 PayPal 立即购买按钮获取库存 list

java - Watson Conversation Java SDK 如何从 ExportEntity 到 CreateEntity?

variables - Paypal ipn/购物车变量

ios - 为仅在以后的 SDK 中可用的类添加属性

java - Java SE 模块从 Netbeans 6.5.1 到 7.0 的过渡

node.js - 我如何使用nodejs在一段时间后动态更新数据?

android - 如何使用改造将 JSON 作为字符串

java - windows下的MPI Java

node.js - Asana API POST 到任务导致服务器错误