addPatch() 공개 메소드

Append Patches to the list.
public addPatch ( Patch $patch )
$patch Patch
예제 #1
0
 /**
  * Update existing billing agreement at paypal
  * @param $agreementId
  * @param array $params
  * @return bool
  * @internal param object $createdAgreement Agreement
  */
 function update($agreementId, $params)
 {
     $patch = new Patch();
     $patch->setOp('replace')->setPath('/')->setValue($params);
     $patchRequest = new PatchRequest();
     $patchRequest->addPatch($patch);
     try {
         $agreement = Agreement::get($agreementId, $this->getAdapter()->getApiContext());
         $agreement->update($patchRequest, $this->getAdapter()->getApiContext());
     } catch (\Exception $ex) {
         //@todo add some logging
     }
     return true;
 }
예제 #2
0
    /**
     * @param $createdPlan
     * @return Plan
     */
    function activate(Plan $createdPlan)
    {
        $patch = new Patch();
        $value = new PayPalModel('{
	       "state":"ACTIVE"
	     }');
        $patch->setOp('replace')->setPath('/')->setValue($value);
        $patchRequest = new PatchRequest();
        $patchRequest->addPatch($patch);
        $createdPlan->update($patchRequest, $this->getAdapter()->getApiContext());
        $result = Plan::get($createdPlan->getId(), $this->getAdapter()->getApiContext());
        if ($result) {
            return ['plan' => $result, 'id' => $result->getId(), 'state' => $result->getState(), 'created' => $result->getCreateTime()];
        }
    }
// # Update a plan
//
// This sample code demonstrate how you can update a billing plan, as documented here at:
// https://developer.paypal.com/webapps/developer/docs/api/#update-a-plan
// API used:  /v1/payments/billing-plans/<Plan-Id>
// ### Making Plan Active
// This example demonstrate how you could activate the Plan.
// Retrieving the Plan object from Create Plan Sample to demonstrate the List
/** @var Plan $createdPlan */
$createdPlan = (require 'CreatePlan.php');
use PayPal\Api\Plan;
use PayPal\Api\PatchRequest;
use PayPal\Api\Patch;
use PayPal\Common\PayPalModel;
try {
    $patch = new Patch();
    $value = new PayPalModel('{
	       "state":"ACTIVE"
	     }');
    $patch->setOp('replace')->setPath('/')->setValue($value);
    $patchRequest = new PatchRequest();
    $patchRequest->addPatch($patch);
    $createdPlan->update($patchRequest, $apiContext);
    $plan = Plan::get($createdPlan->getId(), $apiContext);
} catch (Exception $ex) {
    ResultPrinter::printError("Updated the Plan to Active State", "Plan", null, $patchRequest, $ex);
    exit(1);
}
ResultPrinter::printResult("Updated the Plan to Active State", "Plan", $plan->getId(), $patchRequest, $plan);
return $plan;
예제 #4
0
파일: Plan.php 프로젝트: Roc4rdho/app
 /**
  * Delete a billing plan by passing the ID of the billing plan to the request URI.
  *
  * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
  * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
  * @return bool
  */
 public function delete($apiContext = null, $restCall = null)
 {
     ArgumentValidator::validate($this->getId(), "Id");
     $patchRequest = new PatchRequest();
     $patch = new Patch();
     $value = new PayPalModel('{
         "state":"DELETED"
     }');
     $patch->setOp('replace')->setPath('/')->setValue($value);
     $patchRequest->addPatch($patch);
     return $this->update($patchRequest, $apiContext, $restCall);
 }
예제 #5
0
 public function update($paymentId, array $updateInfo)
 {
     $apiContext = $this->connectionService->getApiContext();
     $dispatcher = $this->connectionService->getDispatcher();
     $payment = $this->get($paymentId);
     $event = new PaymentEvent($payment);
     $dispatcher->dispatch(PaymentEvent::UPDATE_START, $event);
     $patchRequest = new PatchRequest();
     foreach ($updateInfo as $operation => $fields) {
         $patch = new Patch();
         $patch->setOp($operation);
         foreach ($fields as $key => $value) {
             $patch->setPath($key)->setValue($value);
         }
         $patchRequest->addPatch(clone $patch);
     }
     $result = $payment->update($patchRequest, $apiContext);
     $event = new PaymentEvent($payment);
     $dispatcher->dispatch($result, $event);
     return $result;
 }
 function update_webhook($data)
 {
     // auth
     $apiContext = $this->apiContext();
     // set webhooks
     $webhook = new Webhook();
     try {
         $WebhookList = $webhook->get($data['id'], $apiContext);
         $valid = true;
     } catch (Exception $ex) {
         $this->LoggingManager->log(print_r($ex, true), 'DEBUG');
         $valid = false;
     }
     if ($valid === true) {
         $webhookEventTypes = array();
         for ($i = 0, $n = count($data['data']); $i < $n; $i++) {
             if ($data['data'][$i]['name'] != '') {
                 $webhookEvent = new WebhookEventType();
                 $webhookEvent->setName($data['data'][$i]['name']);
                 $webhookEventTypes[] = $webhookEvent;
             }
         }
         $patch = new Patch();
         $patch->setOp("replace")->setPath("/event_types")->setValue($webhookEventTypes);
         $patchRequest = new PatchRequest();
         $patchRequest->addPatch($patch);
     }
     try {
         $WebhookList->update($patchRequest, $apiContext);
         $success = true;
     } catch (Exception $ex) {
         $this->LoggingManager->log(print_r($ex, true), 'DEBUG');
         $success = false;
     }
     $avaliable_data = $this->available_webhooks();
     for ($i = 0, $n = count($avaliable_data); $i < $n; $i++) {
         $this->delete_config($avaliable_data[$i]['name']);
     }
     $sql_data_array = array();
     for ($i = 0, $n = count($data['data']); $i < $n; $i++) {
         if ($data['data'][$i]['name'] != '') {
             $sql_data_array[] = array('config_key' => $data['data'][$i]['name'], 'config_value' => $data['data'][$i]['orders_status']);
         }
     }
     $this->save_config($sql_data_array);
 }
 public function update($creditCardToken, array $updateInfo)
 {
     $apiContext = $this->connectionService->getApiContext();
     $dispatcher = $this->connectionService->getDispatcher();
     $creditCard = $this->getDetails($creditCardToken);
     $creditCardEvent = new CreditCardEvent($creditCard);
     $dispatcher->dispatch(CreditCardEvent::UPDATE_START, $creditCardEvent);
     $patchRequest = new PatchRequest();
     foreach ($updateInfo as $operation => $fields) {
         $allowedOperation = Validation::updateOP($operation);
         if ($allowedOperation) {
             $patch = new Patch();
             $patch->setOp($operation);
             foreach ($fields as $key => $value) {
                 $patch->setPath($key)->setValue($value);
             }
             $patchRequest->addPatch(clone $patch);
         }
     }
     $result = $creditCard->update($patchRequest, $apiContext);
     $creditCardEvent = new CreditCardEvent($result);
     $dispatcher->dispatch(CreditCardEvent::UPDATE_END, $creditCardEvent);
     return true;
 }
예제 #8
0
 /**
  * Adding shipping address to an existing payment.
  *
  * @param Mage_Sales_Model_Quote $quote
  * @return boolean
  */
 public function patchPayment($quote)
 {
     if (Mage::getSingleton('customer/session')->getPayPalPaymentId()) {
         $payment = Payment::get(Mage::getSingleton('customer/session')->getPayPalPaymentId(), $this->_apiContext);
         $patchRequest = new PatchRequest();
         $transactions = $payment->getTransactions();
         if (is_null($transactions[0]->getItemList()->getShippingAddress())) {
             $addressMode = 'add';
         } else {
             $addressMode = 'replace';
         }
         $shippingAddress = $this->buildShippingAddress($quote);
         $addressPatch = new Patch();
         $addressPatch->setOp($addressMode);
         $addressPatch->setPath('/transactions/0/item_list/shipping_address');
         $addressPatch->setValue($shippingAddress);
         $patchRequest->addPatch($addressPatch);
         $response = $payment->update($patchRequest, $this->_apiContext);
         return $response;
     }
     return false;
 }
예제 #9
0
 /**
  * Patches invoice number to PayPal transaction
  * (Magento order increment id)
  *
  * @param $paymentId
  * @param $invoiceNumber
  * @return bool
  */
 public function patchInvoiceNumber($paymentId, $invoiceNumber)
 {
     $payment = Payment::get($paymentId, $this->_apiContext);
     $patchRequest = new PatchRequest();
     $invoiceNumberPatch = new Patch();
     $invoiceNumberPatch->setOp('add');
     $invoiceNumberPatch->setPath('/transactions/0/invoice_number');
     $invoiceNumberPatch->setValue($invoiceNumber);
     $patchRequest->addPatch($invoiceNumberPatch);
     $response = $payment->update($patchRequest, $this->_apiContext);
     return $response;
 }