A JSON patch request.
상속: extends PayPal\Common\PayPalModel
예제 #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()];
        }
    }
 /**
  * @depends testGet
  * @param $agreement Agreement
  */
 public function testUpdate($agreement)
 {
     /** @var Patch[] $request */
     $request = $this->operation['request']['body'][0];
     $patch = new Patch();
     $patch->setOp($request['op']);
     $patch->setPath($request['path']);
     $patch->setValue($request['value']);
     $patches = array();
     $patches[] = $patch;
     $patchRequest = new PatchRequest();
     $patchRequest->setPatches($patches);
     $result = $agreement->update($patchRequest, $this->apiContext, $this->mockPayPalRestCall);
     $this->assertTrue($result);
 }
예제 #4
0
 /**
  * @depends testSerializationDeserialization
  * @param PatchRequest $obj
  */
 public function testGetters($obj)
 {
     $this->assertEquals($obj->getPatches(), PatchTest::getObject());
 }
// # 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;
 /**
  * @depends testGet
  * @param $plan Plan
  * @return Plan
  */
 public function testUpdateChangingState($plan)
 {
     /** @var Patch[] $request */
     $request = $this->operation['request']['body'][0];
     $patch = new Patch();
     $patch->setOp($request['op']);
     $patch->setPath($request['path']);
     $patch->setValue($request['value']);
     $patches = array();
     $patches[] = $patch;
     $patchRequest = new PatchRequest();
     $patchRequest->setPatches($patches);
     $result = $plan->update($patchRequest, $this->apiContext, $this->mockPayPalRestCall);
     $this->assertTrue($result);
     return Plan::get($plan->getId(), $this->apiContext, $this->mockPayPalRestCall);
 }
 /**
  * @depends testGet
  * @param $webhook Webhook
  */
 public function testUpdate($webhook)
 {
     $patches = array();
     foreach ($this->operation['request']['body'] as $request) {
         /** @var Patch[] $request */
         $patch = new Patch();
         $patch->setOp($request['op']);
         $patch->setPath($request['path']);
         $patch->setValue($request['value']);
         if ($request['path'] == "/url") {
             $new_url = $request['value'] . '?rand=' . uniqid();
             $patch->setValue($new_url);
         }
         $patches[] = $patch;
     }
     $patchRequest = new PatchRequest();
     $patchRequest->setPatches($patches);
     $result = $webhook->update($patchRequest, $this->apiContext, $this->mockPayPalRestCall);
     $this->assertNotNull($result);
     $found = false;
     $foundObject = null;
     foreach ($result->getEventTypes() as $eventType) {
         if ($eventType->getName() == "PAYMENT.SALE.REFUNDED") {
             $found = true;
             break;
         }
     }
     $this->assertTrue($found);
 }
예제 #8
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);
 }
 function complete_cart($order_exists = true)
 {
     global $insert_id;
     // check
     $check_query = xtc_db_query("SELECT * \n                                   FROM " . TABLE_PAYPAL_PAYMENT . "\n                                  WHERE payment_id = '" . xtc_db_input($_SESSION['paypal']['paymentId']) . "'");
     if (xtc_db_num_rows($check_query) > 0) {
         $status_id = $this->order_status_tmp;
         if ($status_id < 0) {
             $check_query = xtc_db_query("SELECT orders_status\n                                         FROM " . TABLE_ORDERS . " \n                                        WHERE orders_id = '" . (int) $insert_id . "'");
             $check = xtc_db_fetch_array($check_query);
             $status_id = $check['orders_status'];
         }
         $this->update_order('duplicate call, cancel', $status_id, $insert_id);
         return;
     }
     // auth
     $apiContext = $this->apiContext();
     try {
         // Get the payment Object by passing paymentId
         $payment = Payment::get($_SESSION['paypal']['paymentId'], $apiContext);
     } catch (Exception $ex) {
         $this->LoggingManager->log(print_r($ex, true), 'DEBUG');
         $this->remove_order($insert_id);
         unset($_SESSION['paypal']);
         unset($_SESSION['tmp_oID']);
         xtc_redirect(xtc_href_link(FILENAME_SHOPPING_CART, 'payment_error=' . $this->code, 'NONSSL'));
     }
     // set order
     $order = new order($insert_id);
     $patches_array = array();
     $patchRequest = new PatchRequest();
     $payment_address = new Address();
     $payment_address->setLine1($this->encode_utf8($order->billing['street_address']))->setCity($this->encode_utf8($order->billing['city']))->setState($this->encode_utf8($order->billing['state'] != '' ? xtc_get_zone_code($order->billing['country_id'], $order->billing['zone_id'], $order->billing['state']) : ''))->setPostalCode($this->encode_utf8($order->billing['postcode']))->setCountryCode($this->encode_utf8(isset($order->billing['country_iso_2']) ? $order->billing['country_iso_2'] : $order->billing['country']['iso_code_2']));
     if ($order->billing['suburb'] != '') {
         $payment_address->setLine2($this->encode_utf8($order->billing['suburb']));
     }
     $patch_payment = new Patch();
     $patch_payment->setOp('add')->setPath('/potential_payer_info/billing_address')->setValue($payment_address);
     $patches_array[] = $patch_payment;
     // set address
     $shipping_address = new ShippingAddress();
     $shipping_address->setRecipientName($this->encode_utf8($order->delivery['firstname'] . ' ' . $order->delivery['lastname']))->setLine1($this->encode_utf8($order->delivery['street_address']))->setCity($this->encode_utf8($order->delivery['city']))->setCountryCode($this->encode_utf8(isset($order->delivery['country_iso_2']) ? $order->delivery['country_iso_2'] : $order->delivery['country']['iso_code_2']))->setPostalCode($this->encode_utf8($order->delivery['postcode']))->setState($this->encode_utf8($order->delivery['state'] != '' ? xtc_get_zone_code($order->delivery['country_id'], $order->delivery['zone_id'], $order->delivery['state']) : ''));
     if ($order->delivery['suburb'] != '') {
         $shipping_address->setLine2($this->encode_utf8($order->delivery['suburb']));
     }
     $patch_shipping = new Patch();
     $patch_shipping->setOp('add')->setPath('/transactions/0/item_list/shipping_address')->setValue($shipping_address);
     $patches_array[] = $patch_shipping;
     $patch_invoice = new Patch();
     $patch_invoice->setOp('replace')->setPath('/transactions/0/invoice_number')->setValue($this->get_config('PAYPAL_CONFIG_INVOICE_PREFIX') . $insert_id);
     $patches_array[] = $patch_invoice;
     // set details
     $this->details = new Details();
     // set amount
     $this->amount = new Amount();
     // set totals
     $this->get_totals($order->totals);
     $this->amount->setCurrency($order->info['currency'])->setDetails($this->details);
     $patch_amount = new Patch();
     $patch_amount->setOp('replace')->setPath('/transactions/0/amount')->setValue($this->amount);
     $patches_array[] = $patch_amount;
     // set ItemList
     if ($this->get_config('PAYPAL_ADD_CART_DETAILS') == '0' || $this->check_discount() === true) {
         $item = array();
         $item[0] = new Item();
         $item[0]->setName($this->encode_utf8(MODULE_PAYMENT_PAYPAL_TEXT_ORDER))->setCurrency($order->info['currency'])->setQuantity(1)->setPrice($this->details->getSubtotal());
     } else {
         for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
             $item[$i] = new Item();
             $item[$i]->setName($this->encode_utf8($order->products[$i]['name']))->setCurrency($order->info['currency'])->setQuantity($order->products[$i]['qty'])->setPrice($order->products[$i]['price'])->setSku($order->products[$i]['model'] != '' ? $order->products[$i]['model'] : $order->products[$i]['id']);
         }
     }
     $patch_items = new Patch();
     $patch_items->setOp('replace')->setPath('/transactions/0/item_list/items')->setValue($item);
     $patches_array[] = $patch_items;
     $patchRequest->setPatches($patches_array);
     try {
         // update payment
         $payment->update($patchRequest, $apiContext);
     } catch (Exception $ex) {
         $this->LoggingManager->log(print_r($ex, true), 'DEBUG');
         if ($order_exists === false) {
             unset($_SESSION['paypal']);
             xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code, 'SSL'));
         }
         $this->remove_order($insert_id);
         unset($_SESSION['paypal']);
         unset($_SESSION['tmp_oID']);
         xtc_redirect(xtc_href_link(FILENAME_SHOPPING_CART, 'payment_error=' . $this->code, 'NONSSL'));
     }
     $payment = Payment::get($_SESSION['paypal']['paymentId'], $apiContext);
     // PaymentExecution
     $execution = new PaymentExecution();
     $execution->setPayerId($_SESSION['paypal']['PayerID']);
     try {
         // Execute the payment
         $payment->execute($execution, $apiContext);
     } catch (Exception $ex) {
         $this->LoggingManager->log(print_r($ex, true), 'DEBUG');
         $this->remove_order($insert_id);
         unset($_SESSION['paypal']);
         unset($_SESSION['tmp_oID']);
         xtc_redirect(xtc_href_link(FILENAME_SHOPPING_CART, 'payment_error=' . $this->code, 'NONSSL'));
     }
     // capture
     if (($this->transaction_type == 'order' || $this->transaction_type == 'authorize') && $this->get_config('PAYPAL_CAPTURE_MANUELL') == '0') {
         $this->capture_payment($payment);
     }
     $sql_data_array = array('orders_id' => $insert_id, 'payment_id' => $_SESSION['paypal']['paymentId'], 'payer_id' => $_SESSION['paypal']['PayerID']);
     xtc_db_perform(TABLE_PAYPAL_PAYMENT, $sql_data_array);
     try {
         // Get the payment Object by passing paymentId
         $payment = Payment::get($_SESSION['paypal']['paymentId'], $apiContext);
     } catch (Exception $ex) {
         $this->LoggingManager->log(print_r($ex, true), 'DEBUG');
         $this->remove_order($insert_id);
         unset($_SESSION['paypal']);
         unset($_SESSION['tmp_oID']);
         xtc_redirect(xtc_href_link(FILENAME_SHOPPING_CART, 'payment_error=' . $this->code, 'NONSSL'));
     }
     $status = $this->get_orders_status($payment);
     if ($status['status_id'] < 0) {
         $check_query = xtc_db_query("SELECT orders_status\n                                     FROM " . TABLE_ORDERS . " \n                                    WHERE orders_id = '" . (int) $insert_id . "'");
         $check = xtc_db_fetch_array($check_query);
         $status['status_id'] = $check['orders_status'];
     }
     $this->update_order($status['comment'], $status['status_id'], $insert_id);
 }
예제 #10
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;
 }
예제 #11
0
 public function activateBillingPlan($planId, $apiContext)
 {
     $patch = new Patch();
     $patch->setOp('replace');
     $patch->setPath('/');
     $patch->setValue(array('state' => 'ACTIVE'));
     $patchRequest = new PatchRequest();
     $patchRequest->setPatches(array($patch));
     $plan = new Plan();
     $plan->setId($planId);
     return $plan->update($patchRequest, $apiContext);
 }
예제 #12
0
 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;
 }
// Retrieving the Agreement object from Create Agreement Sample to demonstrate the List
/** @var Agreement $createdAgreement */
$createdAgreement = (require 'CreateBillingAgreementWithCreditCard.php');
use PayPal\Api\Agreement;
use PayPal\Api\PatchRequest;
use PayPal\Api\Patch;
$patch = new Patch();
$patch->setOp('replace')->setPath('/')->setValue(json_decode('{
            "description": "New Description",
            "shipping_address": {
                "line1": "2065 Hamilton Ave",
                "city": "San Jose",
                "state": "CA",
                "postal_code": "95125",
                "country_code": "US"
            }
        }'));
$patchRequest = new PatchRequest();
$patchRequest->addPatch($patch);
try {
    $createdAgreement->update($patchRequest, $apiContext);
    // Lets get the updated Agreement Object
    $agreement = Agreement::get($createdAgreement->getId(), $apiContext);
} catch (Exception $ex) {
    // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
    ResultPrinter::printError("Updated the Agreement with new Description and Updated Shipping Address", "Agreement", null, $patchRequest, $ex);
    exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Updated the Agreement with new Description and Updated Shipping Address", "Agreement", $agreement->getId(), $patchRequest, $agreement);
return $agreement;
예제 #15
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;
 }
예제 #16
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;
 }