示例#1
0
function invoice_details_callback()
{
    if (isset($_POST['inv_id']) && !empty($_POST['inv_id'])) {
        $invid = explode(",", $_POST['inv_id']);
        require_once 'paypal-invoice/PayPalInvoiceAPI.php';
        require_once 'paypal-invoice/credentials.php';
        //NOTE: edit this file with your info!
        $pAPI = new PayPalInvoiceAPI($api_username, $api_password, $api_signature, $app_id);
        foreach ($invid as $inv_id) {
            //update_post_meta( $inv_id, 'auction_active_pay_method', 'invoice' );
            $invoice_id = get_post_meta($inv_id, 'paypal_invoice_id', true);
            $invoice_data = $pAPI->getInvoiceDetails($invoice_id);
            $invoice_stat = '';
            if ($invoice_data['responseEnvelope.ack'] == "Success") {
                $invoice_stat = isset($invoice_data['invoiceDetails.status']) ? $invoice_data['invoiceDetails.status'] : '';
            } else {
                $invoice_stat = __('Failed to connect with PayPal account. Please verify your PayPal credentials or just reload this page.', 'wdm-ultimate-auction');
            }
            if (!empty($invoice_id)) {
                update_post_meta($inv_id, 'auction_invoice_status', $invoice_stat);
            }
        }
    }
    if (isset($_POST['adp_id']) && !empty($_POST['adp_id'])) {
        require_once 'paypal-adaptive/PPBootStrap.php';
        $adpid = explode(",", $_POST['adp_id']);
        foreach ($adpid as $adp_id) {
            //update_post_meta( $adp_id, 'auction_active_pay_method', 'adaptive' );
            $requestEnvelope = new RequestEnvelope("en_US");
            $paymentDetailsReq = new PaymentDetailsRequest($requestEnvelope);
            $payKey = get_post_meta($adp_id, 'paypal_invoice_id', true);
            if ($payKey != "") {
                $paymentDetailsReq->payKey = $payKey;
            }
            //if($_POST['transactionId'] != "") {
            //	$paymentDetailsReq->transactionId = $_POST['transactionId'];
            //}
            //if($_POST['trackingId'] != "") {
            //	$paymentDetailsReq->trackingId = $_POST['trackingId'];
            //}
            $service = new AdaptivePaymentsService(Configuration::getAcctAndConfig());
            try {
                /* wrap API method calls on the service object with a try catch */
                $response = $service->PaymentDetails($paymentDetailsReq);
            } catch (Exception $ex) {
            }
            update_post_meta($adp_id, 'paypal_trans_timestamp', $response->responseEnvelope->timestamp);
            $ack = strtoupper($response->responseEnvelope->ack);
            $pay_stat = '';
            if ($ack != "SUCCESS") {
                $pay_stat = __('Failed to connect with PayPal account. Please verify your PayPal credentials or just reload this page.', 'wdm-ultimate-auction');
            } else {
                $pay_stat = $response->status;
            }
            if (!empty($payKey)) {
                if (strtoupper($pay_stat) == 'CREATED') {
                    update_post_meta($adp_id, 'auction_invoice_status', 'Sent');
                } elseif (strtoupper($pay_stat) == 'COMPLETED') {
                    update_post_meta($adp_id, 'auction_invoice_status', 'Paid');
                } else {
                    update_post_meta($adp_id, 'auction_invoice_status', $pay_stat);
                }
            }
        }
    }
    die;
}
<?php

require_once 'PayPalInvoiceAPI.php';
require_once 'credentials.php';
//NOTE: edit this file with your info!
$ppAPI = new PayPalInvoiceAPI($api_username, $api_password, $api_signature, $app_id);
//required request fields
$req['currencyCode'] = $auction_data['auc_currency'];
$req['merchantEmail'] = $sandbox_seller_email;
$req['payerEmail'] = $auction_data['auc_payer'];
$req['paymentTerms'] = "DueOnReceipt";
//DueOnReceipt, DueOnDateSpecified, Net10, Net15, Net30, or Net45
//include shipping amount in invoice
$req['shippingAmount'] = "";
$req['shippingAmount'] = apply_filters('ua_shipping_data_invoice', $req['shippingAmount'], $auction_data['auc_id'], $auction_data['auc_payer']);
//required item fields
$items[0]['name'] = substr($auction_data['auc_name'], 0, 59);
//have limited to max 60 characters as there is limit by PayPal for this field
$items[0]['quantity'] = "1";
$items[0]['unitPrice'] = $auction_data['auc_bid'];
//some optional fields
//$items[0]['description'] = $auction_data['auc_desc']; //have disabled this as PayPal has limit of 1000 characters for this field and also broken html related issue could arise
$current_time = time();
$items[0]['date'] = date(DATE_ATOM, $current_time);
//date product or service was provided
//$items[0]['taxName'] = "";
//$items[0]['taxRate'] = "";
// For complete field listing, read the example PayPalInvoiceAPI.php and
// https://cms.paypal.com/cms_content/US/en_US/files/developer/PP_InvoicingAPIGuide.pdf
$res = $ppAPI->createAndSendInvoice($req, $items);
if ($res['responseEnvelope.ack'] == "Success") {