贝宝 SDK 非常简单。首先,如果我是你,我会安装他们的示例代码并确保它在你的服务器上工作,根据我以前的经验,很少有 SDK 无法工作并且有 php 版本问题的情况。
其次,在您确定它可以在您的服务器上运行之后,图表流程是:
步骤 1.) SetExpressCheckout - 包含所有必填字段,例如:账单地址、产品购物车总数等...
如果操作正确,您将获得一个令牌,
步骤 2.) GetExpressCheckout - 使用之前获得的令牌,您将通过令牌执行 GetExpressCheckout,如果正确,您将获得:Ack、令牌、PayerID、价值、货币ID,基本上是一个包含所有购买详细信息的对象。
步骤 3.) DoExpressCheckout - 使用从 2 中获取的字段执行 DoExpressCheckout,如下所示:
$path = $pluginfolder.'paypal/lib';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once('services/PayPalAPIInterfaceService/PayPalAPIInterfaceServiceService.php');
require_once('PPLoggingManager.php');
$logger = new PPLoggingManager('DoExpressCheckout');
$token = urlencode( $getToken );
$payerId = urlencode( $getPayerID);
$paymentAction = urlencode( $paymentType);
$orderTotal = new BasicAmountType();
$orderTotal->currencyID = $getCurrencyID;
$orderTotal->value = $getOrderTotal;
$paymentDetails= new PaymentDetailsType();
$paymentDetails->OrderTotal = $orderTotal;
if(isset($notifyURL))
{
$paymentDetails->NotifyURL = $notifyURL;
}
$DoECRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
$DoECRequestDetails->PayerID = $payerId;
$DoECRequestDetails->Token = $token;
$DoECRequestDetails->PaymentAction = $paymentAction;
$DoECRequestDetails->PaymentDetails[0] = $paymentDetails;
$DoECRequest = new DoExpressCheckoutPaymentRequestType();
$DoECRequest->DoExpressCheckoutPaymentRequestDetails = $DoECRequestDetails;
$DoECReq = new DoExpressCheckoutPaymentReq();
$DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest;
/*
* Trying to go a head with the payment and catching errors that might occure.
*/
try {
/* wrap API method calls on the service object with a try catch */
$DoECResponse = $paypalService->DoExpressCheckoutPayment($DoECReq);
} catch (Exception $ex) {
if(isset($ex)) {
$ex_message = $ex->getMessage();
$ex_type = get_class($ex);
if($ex instanceof PPConnectionException) {
$error[] = "Error connecting to " . $ex->getUrl();
$errorCheck = true;
} else if($ex instanceof PPMissingCredentialException || $ex instanceof PPInvalidCredentialException) {
$error[] = $ex->errorMessage();
$errorCheck = true;
} else if($ex instanceof PPConfigurationException) {
$error[] = "Invalid configuration. Please check your configuration file";
$errorCheck = true;
}
}
}
我希望这会有所帮助。