本文整理汇总了PHP中PayPal::DoExpressCheckoutPayment方法的典型用法代码示例。如果您正苦于以下问题:PHP PayPal::DoExpressCheckoutPayment方法的具体用法?PHP PayPal::DoExpressCheckoutPayment怎么用?PHP PayPal::DoExpressCheckoutPayment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PayPal
的用法示例。
在下文中一共展示了PayPal::DoExpressCheckoutPayment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
<?php
// Include required library files.
require_once '../includes/config.php';
require_once '../includes/paypal.class.php';
// Create PayPal object.
$PayPalConfig = array('Sandbox' => $sandbox, 'APIUsername' => $api_username, 'APIPassword' => $api_password, 'APISignature' => $api_signature);
$PayPal = new PayPal($PayPalConfig);
// Prepare request arrays
$DECPFields = array('token' => '', 'payerid' => '', 'returnfmfdetails' => '', 'giftmessage' => '', 'giftreceiptenable' => '', 'giftwrapname' => '', 'giftwrapamount' => '', 'buyermarketingemail' => '', 'surveyquestion' => '', 'surveychoiceselected' => '', 'allowedpaymentmethod' => '');
$Payments = array();
$Payment = array('amt' => '', 'currencycode' => '', 'itemamt' => '', 'shippingamt' => '', 'shippingdiscamt' => '', 'insuranceoptionoffered' => '', 'handlingamt' => '', 'taxamt' => '', 'desc' => '', 'custom' => '', 'invnum' => '', 'notifyurl' => '', 'shiptoname' => '', 'shiptostreet' => '', 'shiptostreet2' => '', 'shiptocity' => '', 'shiptostate' => '', 'shiptozip' => '', 'shiptocountrycode' => '', 'shiptophonenum' => '', 'notetext' => '', 'allowedpaymentmethod' => '', 'paymentaction' => '', 'paymentrequestid' => '', 'sellerpaypalaccountid' => '', 'sellerid' => '', 'sellerusername' => '', 'sellerregistrationdate' => '', 'softdescriptor' => '');
$PaymentOrderItems = array();
$Item = array('name' => '', 'desc' => '', 'amt' => '', 'number' => '', 'qty' => '', 'taxamt' => '', 'itemurl' => '', 'itemcategory' => '', 'itemweightvalue' => '', 'itemweightunit' => '', 'itemheightvalue' => '', 'itemheightunit' => '', 'itemwidthvalue' => '', 'itemwidthunit' => '', 'itemlengthvalue' => '', 'itemlengthunit' => '', 'ebayitemnumber' => '', 'ebayitemauctiontxnid' => '', 'ebayitemorderid' => '', 'ebayitemcartid' => '');
array_push($PaymentOrderItems, $Item);
$Payment['order_items'] = $PaymentOrderItems;
array_push($Payments, $Payment);
$UserSelectedOptions = array('shippingcalculationmode' => '', 'insuranceoptionselected' => '', 'shippingoptionisdefault' => '', 'shippingoptionamount' => '', 'shippingoptionname' => '');
$PayPalRequestData = array('DECPFields' => $DECPFields, 'Payments' => $Payments, 'UserSelectedOptions' => $UserSelectedOptions);
// Pass data into class for processing with PayPal and load the response array into $PayPalResult
$PayPalResult = $PayPal->DoExpressCheckoutPayment($PayPalRequestData);
// Write the contents of the response array to the screen for demo purposes.
echo '<pre />';
print_r($PayPalResult);
示例2: ConfirmPayment
//.........这里部分代码省略.........
$ITEMAMT = 0;
if (sizeof($order->get_items()) > 0) {
foreach ($order->get_items() as $values) {
$_product = $order->get_product_from_item($values);
$qty = absint($values['qty']);
$sku = $_product->get_sku();
$values['name'] = html_entity_decode($values['name'], ENT_NOQUOTES, 'UTF-8');
if ($_product->product_type == 'variation') {
if (empty($sku)) {
$sku = $_product->parent->get_sku();
}
$item_meta = new WC_Order_Item_Meta($values['item_meta']);
$meta = $item_meta->display(true, true);
if (!empty($meta)) {
$values['name'] .= " - " . str_replace(", \n", " - ", $meta);
}
}
/*
* Set price based on tax option.
*/
if (get_option('woocommerce_prices_include_tax') == 'yes') {
$product_price = $order->get_item_subtotal($values, true, false);
} else {
$product_price = $order->get_item_subtotal($values, false, true);
}
$Item = array('name' => $values['name'], 'desc' => '', 'amt' => $product_price, 'number' => $sku, 'qty' => $qty, 'taxamt' => '', 'itemurl' => '', 'itemcategory' => '', 'itemweightvalue' => '', 'itemweightunit' => '', 'itemheightvalue' => '', 'itemheightunit' => '', 'itemwidthvalue' => '', 'itemwidthunit' => '', 'itemlengthvalue' => '', 'itemlengthunit' => '', 'ebayitemnumber' => '', 'ebayitemauctiontxnid' => '', 'ebayitemorderid' => '', 'ebayitemcartid' => '');
array_push($PaymentOrderItems, $Item);
$ITEMAMT += $product_price * $values['qty'];
}
/*
* Get discounts
*/
if ($order->get_cart_discount() > 0) {
foreach (WC()->cart->get_coupons('cart') as $code => $coupon) {
$Item = array('name' => 'Cart Discount', 'number' => $code, 'qty' => '1', 'amt' => '-' . number_format(WC()->cart->coupon_discount_amounts[$code], 2, '.', ''));
array_push($PaymentOrderItems, $Item);
}
$ITEMAMT -= $order->get_cart_discount();
}
if ($order->get_order_discount() > 0) {
foreach (WC()->cart->get_coupons('order') as $code => $coupon) {
$Item = array('name' => 'Order Discount', 'number' => $code, 'qty' => '1', 'amt' => '-' . number_format(WC()->cart->coupon_discount_amounts[$code], 2, '.', ''));
array_push($PaymentOrderItems, $Item);
}
$ITEMAMT -= $order->get_order_discount();
}
/*
* Set shipping and tax values.
*/
if (get_option('woocommerce_prices_include_tax') == 'yes') {
$shipping = $order->get_total_shipping() + $order->get_shipping_tax();
$tax = 0;
} else {
$shipping = $order->get_total_shipping();
$tax = $order->get_total_tax();
}
/*
* Now that we have all items and subtotals
* we can fill in necessary values.
*/
$Payment['itemamt'] = number_format($ITEMAMT, 2, '.', '');
// Required if you specify itemized L_AMT fields. Sum of cost of all items in this order.
/*
* Set tax
*/
if ($tax > 0) {
$Payment['taxamt'] = number_format($tax, 2, '.', '');
// Required if you specify itemized L_TAXAMT fields. Sum of all tax items in this order.
}
/*
* Set shipping
*/
if ($shipping > 0) {
$Payment['shippingamt'] = number_format($shipping, 2, '.', '');
// Total shipping costs for this order. If you specify SHIPPINGAMT you mut also specify a value for ITEMAMT.
}
}
$Payment['order_items'] = $PaymentOrderItems;
array_push($Payments, $Payment);
$UserSelectedOptions = array('shippingcalculationmode' => '', 'insuranceoptionselected' => '', 'shippingoptionisdefault' => '', 'shippingoptionamount' => '', 'shippingoptionname' => '');
$PayPalRequestData = array('DECPFields' => $DECPFields, 'Payments' => $Payments);
// Pass data into class for processing with PayPal and load the response array into $PayPalResult
$PayPalResult = $PayPal->DoExpressCheckoutPayment($PayPalRequestData);
/*
* Log API result
*/
$this->add_log('Test Mode: ' . $this->testmode);
$this->add_log('Endpoint: ' . $this->API_Endpoint);
$this->add_log('Result: ' . print_r($PayPalResult, true));
/*
* Error handling
*/
if ($PayPal->APICallSuccessful($PayPalResult['ACK'])) {
$this->remove_session('TOKEN');
}
/*
* Return the class library result array.
*/
return $PayPalResult;
}