Last active
May 18, 2016 20:53
-
-
Save ChrisFlannagan/b05fd563e339d771eacfff0428549dc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader | |
require __DIR__ . '/api/paypal/PayPal-PHP-SDK/autoload.php'; | |
require __DIR__ . '/api/paypal/PayPal-PHP-SDK/paypal/rest-api-sdk-php/sample/bootstrap.php'; | |
use \PayPal\Api\Address; | |
use PayPal\Api\BillingInfo; | |
use PayPal\Api\Cost; | |
use PayPal\Api\Currency; | |
use PayPal\Api\Invoice; | |
use PayPal\Api\InvoiceAddress; | |
use PayPal\Api\InvoiceItem; | |
use PayPal\Api\MerchantInfo; | |
use PayPal\Api\PaymentTerm; | |
use PayPal\Api\Phone; | |
use PayPal\Api\ShippingInfo; | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>My Site</title> | |
<link rel="stylesheet" type="text/css" href="css/style.css" media="all"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> | |
</head> | |
<body> | |
<?php | |
//admin-header.php contains my database connection credentials | |
require_once( "inc/admin-header.php" ); | |
//I set $more to false here so I know if I need to reload the page with javascript | |
//If there are rows still available this will be set to true and the page will reload | |
$more = false; | |
//Use invoice_update_temp to see if an invoice has been updated already | |
$sql = "SELECT ID, invoice_num, invoice_status FROM orders WHERE invoice_update_temp='0' LIMIT 50"; | |
$result = $con->query( $sql ); | |
$orders = array(); | |
while ( $row = $result->fetch_assoc() ) { | |
$orders[ $row['ID'] ] = $row[ 'sm_invoice_num' ]; | |
$more = true; | |
} | |
?> | |
<div id="results"> | |
<?php | |
//Let's loop through these guys and update their status in the database | |
//also we will set invoice_update_temp to 1 so we know it's been processed | |
foreach( $orders as $order => $inv ) { | |
$invoice = Invoice::get($inv, $apiContext); | |
//Spit out some info so you can see it working | |
echo $invoice->number . '-' . $invoice->status . '<br />'; | |
$sql = "UPDATE orders SET invoice_update_temp='1', invoice_status='" . $invoice->status . "' WHERE ID='" . $order . "'"; | |
mysqli_query( $con, $sql ); | |
} | |
?> | |
</div> | |
<script language="javascript"> | |
<?php | |
if( $more ) { | |
//There's more to do so let's run this again | |
echo 'location.reload();'; | |
} else { | |
//let's reset the database for the next time we want to run this | |
$sql = "UPDATE orders SET invoice_update_temp='0"; | |
mysqli_query( $con, $sql ); | |
} | |
mysqli_close( $con ); | |
?> | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment