Пример #1
0
 /**
  * Suspend billing agreement with paypal
  * @param object $createdAgreement Agreement
  * @param $agreementStateDescription
  * @return bool
  * @internal param string $agreementStateDescriptor
  */
 function suspend($createdAgreement, $agreementStateDescription)
 {
     //Create an Agreement State Descriptor, explaining the reason to suspend.
     $agreementStateDescriptor = new AgreementStateDescriptor();
     $agreementStateDescriptor->setNote($agreementStateDescription);
     $createdAgreement->suspend($agreementStateDescriptor, $this->getAdapter()->getApiContext());
     // Lets get the updated Agreement Object
     return Agreement::get($createdAgreement->getId(), $this->getAdapter()->getApiContext());
 }
Пример #2
0
 /**
  * Update existing billing agreement at paypal
  * @param $agreementId
  * @param string $description
  * @return bool
  * @internal param object $createdAgreement Agreement
  */
 function cancel($agreementId, $description = "Cancelling the agreement")
 {
     $agreement = Agreement::get($agreementId, $this->getAdapter()->getApiContext());
     $agreementStateDescriptor = new AgreementStateDescriptor();
     $agreementStateDescriptor->setNote($description);
     try {
         $agreement->cancel($agreementStateDescriptor, $this->getAdapter()->getApiContext());
     } catch (\Exception $ex) {
         //@todo add some logging
     }
     return true;
 }
Пример #3
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;
 }
Пример #4
0
<?php

// # Suspend an agreement
//
// This sample code demonstrate how you can suspend a billing agreement, as documented here at:
// https://developer.paypal.com/webapps/developer/docs/api/#suspend-an-agreement
// API used: /v1/payments/billing-agreements/<Agreement-Id>/suspend
// 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\AgreementStateDescriptor;
//Create an Agreement State Descriptor, explaining the reason to suspend.
$agreementStateDescriptor = new AgreementStateDescriptor();
$agreementStateDescriptor->setNote("Suspending the agreement");
try {
    $createdAgreement->suspend($agreementStateDescriptor, $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("Suspended the Agreement", "Agreement", null, $agreementStateDescriptor, $ex);
    exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Suspended the Agreement", "Agreement", $agreement->getId(), $agreementStateDescriptor, $agreement);
return $agreement;
 /**
  * @depends testCreateCCAgreement
  * @param $agreement Agreement
  * @return Plan
  */
 public function testGet($agreement)
 {
     $result = Agreement::get($agreement->getId(), $this->apiContext, $this->mockPayPalRestCall);
     $this->assertNotNull($result);
     $this->assertEquals($agreement->getId(), $result->getId());
     return $result;
 }
<?php

// # Reactivate an agreement
//
// This sample code demonstrate how you can reactivate a billing agreement, as documented here at:
// https://developer.paypal.com/webapps/developer/docs/api/#suspend-an-agreement
// API used: /v1/payments/billing-agreements/<Agreement-Id>/suspend
// Retrieving the Agreement object from Suspend Agreement Sample to demonstrate the List
/** @var Agreement $suspendedAgreement */
$suspendedAgreement = (require 'SuspendBillingAgreement.php');
use PayPal\Api\Agreement;
use PayPal\Api\AgreementStateDescriptor;
//Create an Agreement State Descriptor, explaining the reason to suspend.
$agreementStateDescriptor = new AgreementStateDescriptor();
$agreementStateDescriptor->setNote("Reactivating the agreement");
try {
    $suspendedAgreement->reActivate($agreementStateDescriptor, $apiContext);
    // Lets get the updated Agreement Object
    $agreement = Agreement::get($suspendedAgreement->getId(), $apiContext);
} catch (Exception $ex) {
    ResultPrinter::printResult("Reactivate the Agreement", "Agreement", $agreement->getId(), $suspendedAgreement, $ex);
    exit(1);
}
ResultPrinter::printResult("Reactivate the Agreement", "Agreement", $agreement->getId(), $suspendedAgreement, $agreement);
return $agreement;
Пример #7
0
// ## Approval Status
// Determine if the user accepted or denied the request
if (isset($_GET['success']) && $_GET['success'] == 'true') {
    $token = $_GET['token'];
    $agreement = new \PayPal\Api\Agreement();
    try {
        // ## Execute Agreement
        // Execute the agreement by passing in the token
        $agreement->execute($token, $apiContext);
    } catch (Exception $ex) {
        // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
        ResultPrinter::printError("Executed an Agreement", "Agreement", $agreement->getId(), $_GET['token'], $ex);
        exit(1);
    }
    // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
    ResultPrinter::printResult("Executed an Agreement", "Agreement", $agreement->getId(), $_GET['token'], $agreement);
    // ## Get Agreement
    // Make a get call to retrieve the executed agreement details
    try {
        $agreement = \PayPal\Api\Agreement::get($agreement->getId(), $apiContext);
    } catch (Exception $ex) {
        // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
        ResultPrinter::printError("Get Agreement", "Agreement", null, null, $ex);
        exit(1);
    }
    // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
    ResultPrinter::printResult("Get Agreement", "Agreement", $agreement->getId(), null, $agreement);
} else {
    // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
    ResultPrinter::printResult("User Cancelled the Approval", null);
}
Пример #8
0
 /**
  * @dataProvider mockProvider
  * @param Agreement $obj
  */
 public function testGet($obj, $mockApiContext)
 {
     $mockPayPalRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock();
     $mockPayPalRestCall->expects($this->any())->method('execute')->will($this->returnValue(AgreementTest::getJson()));
     $result = $obj->get("agreementId", $mockApiContext, $mockPayPalRestCall);
     $this->assertNotNull($result);
 }
Пример #9
0
 /**
  * Getting the paypal customers for the user
  * @param paypal api_context
  *
  * @return an array with the subscriptions
  */
 public static function getCustomers($apiContext)
 {
     // retrieving the subscriptions
     // !!! Currently unavailable !!!
     // subscription_ids = getSubscriptions()
     $subscriptionIds = array("I-F231FUFEPYG8", "I-WFTN8BULD984", "I-YSRV6BDEPBLG");
     // initializing customer array
     $customers = array();
     // counter (just for testing purposes)
     $i = 0;
     // going through the ids
     foreach ($subscriptionIds as $subId) {
         $i++;
         // just for testing
         // trying to get the agreements one by one
         try {
             // getting the agreement
             $agreement = Agreement::get($subId, $apiContext);
             // transforming agreement to our format
             $formatted_agreement = array('id' => $subId, 'start' => strtotime($agreement->getStartDate()), 'status' => strtolower($agreement->getState()), 'plan' => array('id' => self::generatePlanId($agreement->getPlan())));
             // getting the payer of the agreement
             $payer = $agreement->getPayer();
             // this is not working yet because the API sucks at the moment
             // ... but it'll get better
             // getting the payer_info
             //$payer_info = $payer->getPayerInfo();
             // getting the user id
             //$user_email = $payer_info->getEmail();
             // right now just adding something that makes sense
             $user_email = $i % 2;
             $found = false;
             // finding out whether or not we know this customer
             foreach ($customers as $index => $customer_i) {
                 // matching email
                 if ($customer_i['email'] == $user_email) {
                     // found
                     $found = $index;
                 }
             }
             if ($found === false) {
                 // customer not found
                 // pushing new customer to array
                 array_push($customers, array('zombie' => false, 'email' => $user_email, 'subscriptions' => array('total_count' => 1, 'data' => array($formatted_agreement))));
                 // user's first subscription
             } else {
                 // we already added this customer
                 // adding agreement to the existing ones
                 array_push($customers[$found]['subscriptions']['data'], $formatted_agreement);
                 // adding total count
                 $customers[$found]['subscriptions']['total_count']++;
             }
         } catch (PayPal\Exception\PayPalConnectionException $ex) {
             // an error occoured
             echo '<pre>';
             print_r(json_decode($ex->getData()));
             exit(1);
         }
     }
     // returning object
     return $customers;
 }
Пример #10
0
 /**
  * Suspend billing agreement with paypal
  * @param $agreementId
  * @return bool
  * @internal param object $createdAgreement Agreement
  * @internal param string $agreementStateDescriptor
  */
 function get($agreementId)
 {
     return $agreement = Agreement::get($agreementId, $this->getAdapter()->getApiContext());
 }
// Retrieving the Agreement object from Create Agreement Sample to demonstrate the List
/** @var Agreement $createdAgreement */
$agreement_id = 'P-57V38520G74040029VY7DG6A';
use PayPal\Api\Agreement;
use PayPal\Api\Patch;
use PayPal\Api\PatchRequest;
$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($agreement_id, $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;