PayPal 定期付款未显示在我的买家或商家沙盒帐户中?
PayPal recurring payments not showing in my buyer or merchant sandbox accounts?
我正在使用 Paypal rest-api-sdk-php 包,我似乎无法在我的沙盒买家或 merchant/business账号。
这是我创建计划的代码
public function payPalMakePlan()
{
$plan = new Plan();
$plan->setName('All Tools')->setDescription('test')->setType('INFINITE');
$paymentDefinition = new PaymentDefinition();
$paymentDefinition->setName('Regular Payments')
->setType('REGULAR')
->setFrequency('Month')
->setFrequencyInterval("1")
->setAmount(new Currency(array('value' => 49.99, 'currency' => 'USD')));
$chargeModel = new ChargeModel();
$chargeModel->setType('SHIPPING')->setAmount(new Currency(array('value' => 10, 'currency' => 'USD')));
$paymentDefinition->setChargeModels(array($chargeModel));
$merchantPreferences = new MerchantPreferences();
$baseUrl = ResultPrinter::getBaseUrl();
$merchantPreferences->setReturnUrl("$baseUrl/ExecuteAgreement.php?success=true")
->setCancelUrl("$baseUrl/ExecuteAgreement.php?success=false")
->setAutoBillAmount("yes")
->setInitialFailAmountAction("CONTINUE")
->setMaxFailAttempts("0")
->setSetupFee(new Currency(array('value' => 1, 'currency' => 'USD')));
$plan->setPaymentDefinitions(array($paymentDefinition));
$plan->setMerchantPreferences($merchantPreferences);
$request = clone $plan;
try {
$output = $plan->create($this->apiContext);
} catch (Exception $ex) {
ResultPrinter::printError("Created Plan", "Plan", null, $request, $ex);
exit(1);
}
ResultPrinter::printResult("Created Plan", "Plan", $output->getId(), $request, $output);
try {
$patch = new Patch();
$value = new PayPalModel('{
"state":"ACTIVE"
}');
$patch->setOp('replace')
->setPath('/')
->setValue($value);
$patchRequest = new PatchRequest();
$patchRequest->addPatch($patch);
$plan->update($patchRequest, $this->apiContext);
$plan = Plan::get($output->getId(), $this->apiContext);
} catch (Exception $ex) {
ResultPrinter::printError("Updated the Plan to Active State", "Plan", null, $patchRequest, $ex);
exit(1);
}
ResultPrinter::printResult("Updated the Plan to Active State", "Plan", $plan->getId(), $patchRequest, $plan);
}
这是创建协议的代码
public function payPalProcessPayment()
{
//return $output;
$agreement = new Agreement();
$time = time() + 60;
$startDate = date("Y-m-d", $time) . 'T' . date("H:i:s", $time) . 'Z';
//'2018-03-22T09:13:49Z'
$agreement->setName('Base Agreement')
->setDescription('Basic Agreement')
->setStartDate($startDate);
$plan = new Plan();
$plan->setId('P-5P607214NW3435943FGDG2OI');
$agreement->setPlan($plan);
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$agreement->setPayer($payer);
$shippingAddress = new ShippingAddress();
$shippingAddress->setLine1('111 First Street')
->setCity('Saratoga')
->setState('CA')
->setPostalCode('95070')
->setCountryCode('US');
$agreement->setShippingAddress($shippingAddress);
$request = clone $agreement;
try {
$agreement = $agreement->create($this->apiContext);
$approvalUrl = $agreement->getApprovalLink();
} catch (Exception $ex) {
ResultPrinter::printError("Created Billing Agreement.", "Agreement", null, $request, $ex);
exit(1);
}
ResultPrinter::printResult("Created Billing Agreement. Please visit the URL to Approve.", "Agreement", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $agreement);
//return $agreement;
if (isset($_GET['success']) && $_GET['success'] == 'true')
{
$token = $_GET['token'];
$agreement = new \PayPal\Api\Agreement();
try
{
$agreement->execute($token, $this->apiContext);
}
catch (Exception $ex)
{
ResultPrinter::printError("Executed an Agreement", "Agreement", $agreement->getId(), $_GET['token'], $ex);
exit(1);
}
ResultPrinter::printResult("Executed an Agreement", "Agreement", $agreement->getId(), $_GET['token'], $agreement);
try
{
$agreement = \PayPal\Api\Agreement::get($agreement->getId(), $this->apiContext);
}
catch (Exception $ex)
{
ResultPrinter::printError("Get Agreement", "Agreement", null, null, $ex);
exit(1);
}
ResultPrinter::printResult("Get Agreement", "Agreement", $agreement->getId(), null, $agreement);
}
else
{
ResultPrinter::printResult("User Cancelled the Approval", null);
}
}
这是创建的协议URL
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-20E88883UV349602M
在我点击上面的 URL 登录我的 paypal 买家帐户并点击同意并继续后,我被重定向回我的 "success" 页面,URL 为
https://www.mywebsite.com/ExecuteAgreement.php?success=true&token=EC-20E88883UV349602M
paypal 日志记录设置为 FINE
并显示事件的流程
[15-03-2018 17:17:06] PayPal\Core\PayPalHttpConnection : INFO: POST https://api.sandbox.paypal.com/v1/payments/billing-agreements/
[15-03-2018 17:17:12] PayPal\Core\PayPalHttpConnection : INFO: Response Status : 201
我在这里做什么导致此订阅不显示在任何地方?
我是个白痴,$agreement->execute($token, $this->apiContext);从来没有被处决过 lols.
http://paypal.github.io/PayPal-PHP-SDK/sample/doc/billing/ExecuteAgreement.html
我正在使用 Paypal rest-api-sdk-php 包,我似乎无法在我的沙盒买家或 merchant/business账号。
这是我创建计划的代码
public function payPalMakePlan()
{
$plan = new Plan();
$plan->setName('All Tools')->setDescription('test')->setType('INFINITE');
$paymentDefinition = new PaymentDefinition();
$paymentDefinition->setName('Regular Payments')
->setType('REGULAR')
->setFrequency('Month')
->setFrequencyInterval("1")
->setAmount(new Currency(array('value' => 49.99, 'currency' => 'USD')));
$chargeModel = new ChargeModel();
$chargeModel->setType('SHIPPING')->setAmount(new Currency(array('value' => 10, 'currency' => 'USD')));
$paymentDefinition->setChargeModels(array($chargeModel));
$merchantPreferences = new MerchantPreferences();
$baseUrl = ResultPrinter::getBaseUrl();
$merchantPreferences->setReturnUrl("$baseUrl/ExecuteAgreement.php?success=true")
->setCancelUrl("$baseUrl/ExecuteAgreement.php?success=false")
->setAutoBillAmount("yes")
->setInitialFailAmountAction("CONTINUE")
->setMaxFailAttempts("0")
->setSetupFee(new Currency(array('value' => 1, 'currency' => 'USD')));
$plan->setPaymentDefinitions(array($paymentDefinition));
$plan->setMerchantPreferences($merchantPreferences);
$request = clone $plan;
try {
$output = $plan->create($this->apiContext);
} catch (Exception $ex) {
ResultPrinter::printError("Created Plan", "Plan", null, $request, $ex);
exit(1);
}
ResultPrinter::printResult("Created Plan", "Plan", $output->getId(), $request, $output);
try {
$patch = new Patch();
$value = new PayPalModel('{
"state":"ACTIVE"
}');
$patch->setOp('replace')
->setPath('/')
->setValue($value);
$patchRequest = new PatchRequest();
$patchRequest->addPatch($patch);
$plan->update($patchRequest, $this->apiContext);
$plan = Plan::get($output->getId(), $this->apiContext);
} catch (Exception $ex) {
ResultPrinter::printError("Updated the Plan to Active State", "Plan", null, $patchRequest, $ex);
exit(1);
}
ResultPrinter::printResult("Updated the Plan to Active State", "Plan", $plan->getId(), $patchRequest, $plan);
}
这是创建协议的代码
public function payPalProcessPayment()
{
//return $output;
$agreement = new Agreement();
$time = time() + 60;
$startDate = date("Y-m-d", $time) . 'T' . date("H:i:s", $time) . 'Z';
//'2018-03-22T09:13:49Z'
$agreement->setName('Base Agreement')
->setDescription('Basic Agreement')
->setStartDate($startDate);
$plan = new Plan();
$plan->setId('P-5P607214NW3435943FGDG2OI');
$agreement->setPlan($plan);
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$agreement->setPayer($payer);
$shippingAddress = new ShippingAddress();
$shippingAddress->setLine1('111 First Street')
->setCity('Saratoga')
->setState('CA')
->setPostalCode('95070')
->setCountryCode('US');
$agreement->setShippingAddress($shippingAddress);
$request = clone $agreement;
try {
$agreement = $agreement->create($this->apiContext);
$approvalUrl = $agreement->getApprovalLink();
} catch (Exception $ex) {
ResultPrinter::printError("Created Billing Agreement.", "Agreement", null, $request, $ex);
exit(1);
}
ResultPrinter::printResult("Created Billing Agreement. Please visit the URL to Approve.", "Agreement", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $agreement);
//return $agreement;
if (isset($_GET['success']) && $_GET['success'] == 'true')
{
$token = $_GET['token'];
$agreement = new \PayPal\Api\Agreement();
try
{
$agreement->execute($token, $this->apiContext);
}
catch (Exception $ex)
{
ResultPrinter::printError("Executed an Agreement", "Agreement", $agreement->getId(), $_GET['token'], $ex);
exit(1);
}
ResultPrinter::printResult("Executed an Agreement", "Agreement", $agreement->getId(), $_GET['token'], $agreement);
try
{
$agreement = \PayPal\Api\Agreement::get($agreement->getId(), $this->apiContext);
}
catch (Exception $ex)
{
ResultPrinter::printError("Get Agreement", "Agreement", null, null, $ex);
exit(1);
}
ResultPrinter::printResult("Get Agreement", "Agreement", $agreement->getId(), null, $agreement);
}
else
{
ResultPrinter::printResult("User Cancelled the Approval", null);
}
}
这是创建的协议URL
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-20E88883UV349602M
在我点击上面的 URL 登录我的 paypal 买家帐户并点击同意并继续后,我被重定向回我的 "success" 页面,URL 为
https://www.mywebsite.com/ExecuteAgreement.php?success=true&token=EC-20E88883UV349602M
paypal 日志记录设置为 FINE
并显示事件的流程
[15-03-2018 17:17:06] PayPal\Core\PayPalHttpConnection : INFO: POST https://api.sandbox.paypal.com/v1/payments/billing-agreements/
[15-03-2018 17:17:12] PayPal\Core\PayPalHttpConnection : INFO: Response Status : 201
我在这里做什么导致此订阅不显示在任何地方?
我是个白痴,$agreement->execute($token, $this->apiContext);从来没有被处决过 lols.
http://paypal.github.io/PayPal-PHP-SDK/sample/doc/billing/ExecuteAgreement.html