本文整理汇总了PHP中PayPal::NVPToArray方法的典型用法代码示例。如果您正苦于以下问题:PHP PayPal::NVPToArray方法的具体用法?PHP PayPal::NVPToArray怎么用?PHP PayPal::NVPToArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PayPal
的用法示例。
在下文中一共展示了PayPal::NVPToArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ConfirmPayment
//.........这里部分代码省略.........
*/
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'];
}
/**
* Add custom Woo cart fees as line items
*/
foreach (WC()->cart->get_fees() as $fee) {
$Item = array('name' => $fee->name, 'desc' => '', 'amt' => number_format($fee->amount, 2, '.', ''), 'number' => $fee->id, 'qty' => 1, 'taxamt' => '', 'itemurl' => '', 'itemcategory' => '', 'itemweightvalue' => '', 'itemweightunit' => '', 'itemheightvalue' => '', 'itemheightunit' => '', 'itemwidthvalue' => '', 'itemwidthunit' => '', 'itemlengthvalue' => '', 'itemlengthunit' => '', 'ebayitemnumber' => '', 'ebayitemauctiontxnid' => '', 'ebayitemorderid' => '', 'ebayitemcartid' => '');
/**
* The gift wrap amount actually has its own parameter in
* DECP, so we don't want to include it as one of the line
* items.
*/
if ($Item['number'] != 'gift-wrap') {
array_push($PaymentOrderItems, $Item);
$ITEMAMT += $fee->amount * $Item['qty'];
}
$ctr++;
}
/*
* 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);
$PayPalRequest = isset($PayPalResult['RAWREQUEST']) ? $PayPalResult['RAWREQUEST'] : '';
$PayPalResponse = isset($PayPalResult['RAWRESPONSE']) ? $PayPalResult['RAWRESPONSE'] : '';
$this->add_log('Request: ' . print_r($PayPal->NVPToArray($PayPal->MaskAPIResult($PayPalRequest)), true));
$this->add_log('Response: ' . print_r($PayPal->NVPToArray($PayPal->MaskAPIResult($PayPalResponse)), true));
/*
* Error handling
*/
if ($PayPal->APICallSuccessful($PayPalResult['ACK'])) {
$this->remove_session('TOKEN');
}
/*
* Return the class library result array.
*/
return $PayPalResult;
}
示例2: isset
$shipping_country_code = isset($_POST['SHIPTOCOUNTRY']) ? $_POST['SHIPTOCOUNTRY'] : '';
// Here, we may setup static shipping and tax options, or we could hit a 3rd party
// web service API (eg. UPS, FedEx, USPS) to gather rates in real-time.
//
//
//
// Now we can generate a response for PayPal based on our new shipping values we got back from our carrier API.
$CBFields = array();
// Gather shipping options. If you're pulling rates from a carrier API you would be looping through
// their response in order to populate $ShippingOptions. Here, we're doing it manually for sample purposes.
$ShippingOptions = array();
$Option = array('l_shippingoptionisdefault' => 'true', 'l_shippingoptionname' => 'UPS', 'l_shipingpoptionlabel' => 'UPS', 'l_shippingoptionamount' => '5.00', 'l_taxamt' => '0.00', 'l_insuranceamount' => '1.00');
array_push($ShippingOptions, $Option);
$Option = array('l_shippingoptionisdefault' => 'false', 'l_shippingoptionname' => 'UPS', 'l_shipingpoptionlabel' => 'UPS', 'l_shippingoptionamount' => '20.00', 'l_taxamt' => '0.00', 'l_insuranceamount' => '1.00');
array_push($ShippingOptions, $Option);
$callback_data_request_array = array('CBFields' => $CBFields, 'ShippingOptions' => $ShippingOptions);
// Now we pass the data into the class library which will return an NVP string
$callback_data_response = $paypal->CallbackResponse($callback_data_request_array);
// Gather the request data that PayPal sent us in case we need to log it somehow to see what's available.
$request_content = '';
foreach ($_POST as $var => $val) {
$request_content .= '&' . $var . '=' . urldecode($val);
}
// Pass the shipping/tax data into the library to obtain an NVP string that we'll
// simply output as a web service response back to PayPal.
$response_content_body = '';
$response_content = $paypal->NVPToArray($callback_data_response);
foreach ($response_content as $var => $val) {
$response_content_body .= $var . ': ' . urldecode($val) . '<br />';
}
echo $callback_data_response;
示例3: array
//.........这里部分代码省略.........
$PaymentDetails['shippingamt'] = $shipping;
// Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt.
}
}
/**
* Add custom Woo cart fees as line items
*/
$item_loop = 0;
foreach (WC()->cart->get_fees() as $fee) {
$Item = array('name' => $fee->name, 'desc' => '', 'amt' => number_format($fee->amount, 2, '.', ''), 'number' => $fee->id, 'qty' => 1, 'taxamt' => '', 'itemurl' => '', 'itemcategory' => '', 'itemweightvalue' => '', 'itemweightunit' => '', 'itemheightvalue' => '', 'itemheightunit' => '', 'itemwidthvalue' => '', 'itemwidthunit' => '', 'itemlengthvalue' => '', 'itemlengthunit' => '', 'ebayitemnumber' => '', 'ebayitemauctiontxnid' => '', 'ebayitemorderid' => '', 'ebayitemcartid' => '');
array_push($OrderItems, $Item);
$ITEMAMT += $fee->amount * $Item['qty'];
$item_loop++;
}
$PaymentDetails['itemamt'] = number_format($ITEMAMT, 2, '.', '');
// Required if you include itemized cart details. (L_AMTn, etc.) Subtotal of items not including S&H, or tax.
/**
* 3D Secure Params
*/
if ($this->enable_3dsecure) {
$Secure3D = array('authstatus3d' => $centinelPAResStatus, 'mpivendor3ds' => $centinelEnrolled, 'cavv' => $centinelCavv, 'eci3ds' => $centinelEciFlag, 'xid' => $centinelXid);
} else {
$Secure3D = array();
}
$PayPalRequestData = array('DPFields' => $DPFields, 'CCDetails' => $CCDetails, 'PayerInfo' => $PayerInfo, 'BillingAddress' => $BillingAddress, 'ShippingAddress' => $ShippingAddress, 'PaymentDetails' => $PaymentDetails, 'OrderItems' => $OrderItems, 'Secure3D' => $Secure3D);
if ($this->debug) {
$log = $PayPalRequestData;
$log['CCDetails']['acct'] = '****';
$log['CCDetails']['cvv2'] = '****';
$this->log->add('paypal-pro', 'Do payment request ' . print_r($log, true));
}
// Pass data into class for processing with PayPal and load the response array into $PayPalResult
$PayPalResult = $PayPal->DoDirectPayment($PayPalRequestData);
if ($this->debug) {
$PayPalRequest = isset($PayPalResult['RAWREQUEST']) ? $PayPalResult['RAWREQUEST'] : '';
$PayPalResponse = isset($PayPalResult['RAWRESPONSE']) ? $PayPalResult['RAWRESPONSE'] : '';
$this->log->add('paypal-pro', 'Request: ' . print_r($PayPal->NVPToArray($PayPal->MaskAPIResult($PayPalRequest)), true));
$this->log->add('paypal-pro', 'Response: ' . print_r($PayPal->NVPToArray($PayPal->MaskAPIResult($PayPalResponse)), true));
}
if (empty($PayPalResult)) {
throw new Exception(__('Empty PayPal response.', 'paypal-for-woocommerce'));
}
if ($PayPal->APICallSuccessful($PayPalResult['ACK'])) {
// Add order note
$order->add_order_note(sprintf(__('PayPal Pro payment completed (Transaction ID: %s, Correlation ID: %s)', 'paypal-for-woocommerce'), $PayPalResult['TRANSACTIONID'], $PayPalResult['CORRELATIONID']));
//$order->add_order_note("PayPal Results: ".print_r($PayPalResult,true));
/**
* Add order notes for AVS result
*/
$avs_response_code = isset($PayPalResult['AVSCODE']) ? $PayPalResult['AVSCODE'] : '';
$avs_response_message = $PayPal->GetAVSCodeMessage($avs_response_code);
$avs_response_order_note = __('Address Verification Result', 'paypal-for-woocommerce');
$avs_response_order_note .= "\n";
$avs_response_order_note .= $avs_response_code;
$avs_response_order_note .= $avs_response_message != '' ? ' - ' . $avs_response_message : '';
$order->add_order_note($avs_response_order_note);
/**
* Add order notes for CVV2 result
*/
$cvv2_response_code = isset($PayPalResult['CVV2MATCH']) ? $PayPalResult['CVV2MATCH'] : '';
$cvv2_response_message = $PayPal->GetCVV2CodeMessage($cvv2_response_code);
$cvv2_response_order_note = __('Card Security Code Result', 'paypal-for-woocommerce');
$cvv2_response_order_note .= "\n";
$cvv2_response_order_note .= $cvv2_response_code;
$cvv2_response_order_note .= $cvv2_response_message != '' ? ' - ' . $cvv2_response_message : '';
$order->add_order_note($cvv2_response_order_note);
// Payment complete
$order->payment_complete();
// Remove cart
WC()->cart->empty_cart();
// Return thank you page redirect
return array('result' => 'success', 'redirect' => $this->get_return_url($order));
} else {
// Get error message
$error_code = isset($PayPalResult['ERRORS'][0]['L_ERRORCODE']) ? $PayPalResult['ERRORS'][0]['L_ERRORCODE'] : '';
$long_message = isset($PayPalResult['ERRORS'][0]['L_LONGMESSAGE']) ? $PayPalResult['ERRORS'][0]['L_LONGMESSAGE'] : '';
$error_message = $error_code . '-' . $long_message;
// Notice admin if has any issue from PayPal
if ($this->error_email_notify) {
$admin_email = get_option("admin_email");
$message .= __("DoDirectPayment API call failed.", "paypal-for-woocommerce") . "\n\n";
$message .= __('Error Code: ', 'paypal-for-woocommerce') . $error_code . "\n";
$message .= __('Detailed Error Message: ', 'paypal-for-woocommerce') . $long_message . "\n";
wp_mail($admin_email, "PayPal Pro Error Notification", $message);
}
if ($this->debug) {
$this->log->add('paypal-pro', 'Error ' . print_r($PayPalResult['ERRORS'], true));
}
$order->update_status('failed', sprintf(__('PayPal Pro payment failed (Correlation ID: %s). Payment was rejected due to an error: %s', 'paypal-for-woocommerce'), $PayPalResult['CORRELATIONID'], '(' . $PayPalResult['L_ERRORCODE0'] . ') ' . '"' . $error_message . '"'));
// Generate error message based on Error Display Type setting
if ($this->error_display_type == 'detailed') {
throw new Exception(__($error_message, 'paypal-for-woocommerce'));
wc_add_notice(__('Payment error:', 'paypal-for-woocommerce') . ' ' . $error_message, "error");
} else {
throw new Exception(__('There was a problem connecting to the payment gateway.', 'paypal-for-woocommerce'));
wc_add_notice(__('Payment error:', 'paypal-for-woocommerce') . ' ' . $error_message, "error");
}
return;
}
}