*/
/* This example demostrats line item shipping
 */
chdir("..");
require_once 'library/googleresponse.php';
require_once 'library/googlemerchantcalculations.php';
require_once 'library/googleresult.php';
require_once 'library/googlerequest.php';
define('RESPONSE_HANDLER_ERROR_LOG_FILE', 'googleerror.log');
define('RESPONSE_HANDLER_LOG_FILE', 'googlemessage.log');
$merchant_id = "";
// Your Merchant ID
$merchant_key = "";
// Your Merchant Key
$server_type = "sandbox";
// change this to go live
$currency = 'USD';
// set to GBP if in the UK
$certificate_path = "";
// set your SSL CA cert path
$Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency);
$GRequest->SetCertificatePath($certificate_path);
$item1 = new GoogleShipItem('SKU_1');
$item1->AddTrackingData('USPS', '123123adjsh123');
$item2 = new GoogleShipItem('SKU_2');
$item2->AddTrackingData('USPS', '123123adjsh123');
$item2->AddTrackingData('fedex', 'adajs549p80789163');
$items = array($item1, $item2, new GoogleShipItem('SKU_3', array(array('carrier' => 'DHL', 'tracking-number' => 'akjshdj12323'), array('carrier' => 'USPS', 'tracking-number' => 'aasd4a4sd465a3'))), new GoogleShipItem('SKU_4', array(array('carrier' => 'UPS', 'tracking-number' => '09876543231'))));
$Grequest->SendShipItems('123456789', $items);
$Grequest->SendCancelItems('123456789', array($item1, $item2), "reason", "comment");
$Grequest->SendReturnItems('123456789', $items);
Esempio n. 2
0
 /**
  * @param string $message
  * @param array $params
  *
  * @return bool|object
  */
 public function cancelSubscription(&$message = '', $params = array())
 {
     $orderNo = CRM_Utils_Array::value('subscriptionId', $params);
     $merchant_id = $this->_paymentProcessor['user_name'];
     $merchant_key = $this->_paymentProcessor['password'];
     $server_type = $this->_mode == 'test' ? 'sandbox' : '';
     $googleRequest = new GoogleRequest($merchant_id, $merchant_key, $server_type);
     $result = $googleRequest->SendCancelItems($orderNo, array(), 'Cancelled by admin', '');
     $message = "{$result[0]}: {$result[1]}";
     if ($result[0] != 200) {
         return self::error($result[0], $result[1]);
     }
     return TRUE;
 }
             $gitem = new GoogleItem($dbItem->name, $dbItem->description, $dbOrderItem->quantity, $dbItem->price);
             // Unit price
             $refundAmount += $dbOrderItem->quantity * $dbItem->price;
             $Gresponse->log->LogResponse("refund subtotal: " . $refundAmount);
             //set item unique id
             $Gresponse->log->LogResponse("Set Merchant Id" . $dbItem->id);
             $gitem->SetMerchantItemId($dbItem->id);
             array_push($itemsToCancel, $gitem);
         }
     }
     if (count($itemsToCancel) > 0) {
         //Compare total quantity of order items with cancel items to update order status
         $orderItems = db_getOrderItems($dborder->id);
         $Gresponse->log->LogResponse("From " . count($orderItems) . " items, " . count($itemsToCancel) . " will be cancelled");
         $response = $Grequest->SendRefundOrder($dborder->ordernumber, $refundAmount, "Items could not be processed in Quota System. The most common reason " . "is that there were not enough resources to satisfy this request", "Contact the administrator for further details.");
         $response = $Grequest->SendCancelItems($dborder->ordernumber, $itemsToCancel, "Items could not be processed in Quota System. The most common reason " . "is that there were not enough resources to satisfy this request");
         db_setOrderRefund($dborder->id, $dborder->refund + $refundAmount);
     }
     break;
 case 'PAYMENT_DECLINED':
     $Gresponse->log->LogResponse("Canceling order " . $data[$root]['google-order-number']['VALUE']);
     $response = $Grequest->SendCancelOrder($data[$root]['google-order-number']['VALUE'], "Payment Declined", "Contact Google Checkout for further details.");
     $Grequest->SendBuyerMessage($data[$root]['google-order-number']['VALUE'], "Sorry, your payment has been declined", true);
     $Gresponse->log->LogResponse("Response: " . array_to_json($response));
     break;
 case 'CANCELLED':
     $Gresponse->log->LogResponse("Cancelled " + $data[$root]['google-order-number']['VALUE']);
     $order = db_getOrderByOrderNumber($data[$root]['google-order-number']['VALUE']);
     cancelTransaction($order->id);
     $orderItems = db_getOrderItems($orderid);
     foreach ($orderItems as $orderItem) {
Esempio n. 4
0
 if ($refundAmount > 0) {
     $itemToCancel = array();
     //create a google item
     $gitem = new GoogleItem($dbItem->name, $dbItem->description, $dbOrderItem->quantity, $dbItem->price);
     // Unit price
     //set item unique id
     $gitem->SetMerchantItemId($dbItem->id);
     array_push($itemsToCancel, $gitem);
     //Refund total or partial item price
     $gresponse = $Grequest->SendRefundOrder($dbOrder->ordernumber, $refundAmount, "Item has been refunded by the administrator of the quota store." . "Contact the administrator for further details.");
     if ($gresponse[0] == 200) {
         //If the refund amount is not the total of the orderItem,
         //item cannot be cancelled
         db_setOrderRefund($dbOrder->id, $dbOrder->refund + $refundAmount);
         if ($percentageReturned == 1) {
             $gresponse = $Grequest->SendCancelItems($dbOrder->ordernumber, $itemsToCancel, "Item has been cancelled by the administrator of the quota store." . "Contact the administrator for further details.");
             if ($gresponse[0] == 200) {
                 db_cancelOrderItem($dbOrder->id, $dbItem->id);
                 $success = true;
             } else {
                 $success = false;
                 $message = "Google could not cancel item " . $dbItem->name;
             }
         } else {
             db_cancelOrderItem($dbOrder->id, $dbItem->id);
             $success = true;
         }
     } else {
         $success = false;
         $message = "Google could not refund the amount of " . $refundAmount . " to the order " . $dbOrder->ordernumber . ".";
     }