예제 #1
0
 private function pay_vendors($vendors)
 {
     if (empty($vendors)) {
         $return = array('status' => 'error', 'msg' => __('No vendors found to pay. Maybe they haven\'t set a PayPal address?', 'eddc'));
         $this->mail_results($return);
         return $return;
     }
     $this->include_paypal_sdk();
     $logger = new PPLoggingManager('MassPay');
     $massPayRequest = new MassPayRequestType();
     $massPayRequest->MassPayItem = array();
     $total_pay = 0;
     foreach ($vendors as $user_paypal => $user) {
         // Don't attempt to process payments for users that owe the admin money
         if ($user['total_due'] <= 0) {
             continue;
         }
         $total_pay += $user['total_due'];
         $masspayItem = new MassPayRequestItemType();
         $masspayItem->Amount = new BasicAmountType(edd_get_currency(), $user['total_due']);
         $masspayItem->ReceiverEmail = $user_paypal;
         $massPayRequest->MassPayItem[] = $masspayItem;
     }
     $massPayReq = new MassPayReq();
     $massPayReq->MassPayRequest = $massPayRequest;
     $paypalService = new PayPalAPIInterfaceServiceService();
     // Wrap API method calls on the service object with a try catch
     try {
         $massPayResponse = $paypalService->MassPay($massPayReq);
     } catch (Exception $ex) {
         $return = array('status' => 'error', 'msg' => sprintf(__('Error: %s', 'eddc'), $ex->getMessage()), 'total' => $total_pay);
         return $return;
     }
     $return = array();
     if (isset($massPayResponse)) {
         if ($massPayResponse->Ack === 'Success') {
             if ($this->purge_user_meta($vendors)) {
                 $return = array('status' => 'updated', 'msg' => __('All due commission has been paid for.', 'eddc'), 'total' => $total_pay);
             } else {
                 $return = array('status' => 'error', 'msg' => __('All due commission has been paid for, but I could not clear it from their profiles due to an internal error. Commission will still be listed as due. Please manually mark the commission as paid from the Commissions page.', 'eddc'), 'total' => $total_pay);
             }
         } else {
             $return = array('status' => 'error', 'msg' => sprintf('%s. %s (%s): %s.', $massPayResponse->Ack, $massPayResponse->Errors->ShortMessage, $massPayResponse->Errors->ErrorCode, $massPayResponse->Errors->LongMessage), 'total' => $total_pay);
         }
     }
     $this->mail_results($return);
     return $return;
 }
예제 #2
0
 function processWithdrawalRequests($ids = array())
 {
     global $database;
     require_once 'PPBootStrap.php';
     // The MassPay API lets you send payments to up to 250 recipients with a single API call.
     $ids = array_slice($ids, 0, 250);
     $requests = $database->getWithdrawalRequestsById($ids);
     $massPayItems = array();
     $processed_ids = array();
     foreach ($requests as $request) {
         $masspayItem = new MassPayRequestItemType();
         $masspayItem->Amount = new BasicAmountType('USD', round($request['amount'], 2));
         $masspayItem->ReceiverEmail = $request['paypalemail'];
         $massPayItems[] = $masspayItem;
         $processed_ids[] = $request['id'];
     }
     $massPayReq = new MassPayReq();
     $massPayReq->MassPayRequest = new MassPayRequestType($massPayItems);
     $service = new PayPalAPIInterfaceServiceService(array('mode' => PAYPAL_MODE, 'acct1.UserName' => PAYPAL_USERNAME, 'acct1.Password' => PAYPAL_PASSWORD, 'acct1.Signature' => PAYPAL_SIGNATURE));
     try {
         $response = $service->MassPay($massPayReq);
     } catch (Exception $e) {
         $error = 'Mass Pay Service Error Message: ' . $e->getMessage();
         $_SESSION['process_withdrawal_requests_message'] = array('type' => 'error', 'message' => $error);
         return false;
     }
     if (strtoupper($response->Ack) == 'SUCCESS') {
         $database->updateWithdrawalRequests($processed_ids);
         $_SESSION['process_withdrawal_requests_message'] = array('type' => 'success', 'message' => 'Successfully processed ' . count($processed_ids) . ' withdrawal requests');
         return true;
     } else {
         $error = 'Mass Pay Error Message:<br/>';
         foreach ($response->Errors as $e) {
             $error .= $e->LongMessage . '<br/>';
         }
         $_SESSION['process_withdrawal_requests_message'] = array('type' => 'error', 'message' => $error);
         return false;
     }
 }
예제 #3
0
$massPayReq->MassPayRequest = $massPayRequest;
/*
 * 	 ## Creating service wrapper object
Creating service wrapper object to make API call and loading
Configuration::getAcctAndConfig() returns array that contains credential and config parameters
*/
$paypalService = new PayPalAPIInterfaceServiceService(Configuration::getAcctAndConfig());
// required in third party permissioning
if ($_POST['accessToken'] != null && $_POST['tokenSecret'] != null) {
    $cred = new PPSignatureCredential(USERNAME, PASSWORD, SIGNATURE);
    $cred->setThirdPartyAuthorization(new PPTokenAuthorization($_POST['accessToken'], $_POST['tokenSecret']));
}
try {
    /* wrap API method calls on the service object with a try catch */
    if ($_POST['accessToken'] != null && $_POST['tokenSecret'] != null) {
        $massPayResponse = $paypalService->MassPay($massPayReq, $cred);
    } else {
        $massPayResponse = $paypalService->MassPay($massPayReq);
    }
} catch (Exception $ex) {
    include_once "../Error.php";
    exit;
}
if (isset($massPayResponse)) {
    echo "<table>";
    echo "<tr><td>Ack :</td><td><div id='Ack'>{$massPayResponse->Ack}</div> </td></tr>";
    echo "</table>";
    echo "<pre>";
    print_r($massPayResponse);
    echo "</pre>";
}
예제 #4
0
 public function payMass()
 {
     $logger = new PPLoggingManager('MassPay');
     // ## MassPayReq
     // Details of each payment.
     // `Note:
     // A single MassPayRequest can include up to 250 MassPayItems.`
     $massPayReq = new MassPayReq();
     $massPayItemArray = array();
     // `Amount` for the payment which contains
     //
     // * `Currency Code`
     // * `Amount`
     $amount1 = new BasicAmountType("USD", "4.00");
     $massPayRequestItem1 = new MassPayRequestItemType($amount1);
     // Email Address of receiver
     $massPayRequestItem1->ReceiverEmail = "*****@*****.**";
     // `Amount` for the payment which contains
     //
     // * `Currency Code`
     // * `Amount`
     $amount2 = new BasicAmountType("USD", "3.00");
     $massPayRequestItem2 = new MassPayRequestItemType($amount2);
     // Email Address of receiver
     $massPayRequestItem2->ReceiverEmail = "*****@*****.**";
     // `Amount` for the payment which contains
     //
     // * `Currency Code`
     // * `Amount`
     $amount3 = new BasicAmountType("USD", "7.00");
     $massPayRequestItem3 = new MassPayRequestItemType($amount3);
     // Email Address of receiver
     $massPayRequestItem3->ReceiverEmail = "*****@*****.**";
     $massPayItemArray[0] = $massPayRequestItem2;
     $massPayItemArray[1] = $massPayRequestItem1;
     $massPayItemArray[2] = $massPayRequestItem3;
     $massPayRequest = new MassPayRequestType($massPayItemArray);
     $massPayReq->MassPayRequest = $massPayRequest;
     // ## Creating service wrapper object
     // Creating service wrapper object to make API call and loading
     // configuration file for your credentials and endpoint
     $service = new PayPalAPIInterfaceServiceService();
     try {
         // ## Making API call
         // Invoke the appropriate method corresponding to API in service
         // wrapper object
         $response = $service->MassPay($massPayReq);
     } catch (Exception $ex) {
         $logger->error("Error Message : " + $ex->getMessage());
     }
     // ## Accessing response parameters
     // You can access the response parameters using getter methods in
     // response object as shown below
     // ### Success values
     if ($response->Ack == "Success") {
         $logger->log("Mass Pay successful");
     } else {
         $logger->error("API Error Message : " . $response->Errors[0]->LongMessage);
     }
     return $response;
 }