Example #1
0
 /**
  * @dataProvider mockProvider
  * @param Plan $obj
  */
 public function testGet($obj, $mockApiContext)
 {
     $mockPayPalRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock();
     $mockPayPalRestCall->expects($this->any())->method('execute')->will($this->returnValue(PlanTest::getJson()));
     $result = $obj->get("planId", $mockApiContext, $mockPayPalRestCall);
     $this->assertNotNull($result);
 }
Example #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()];
        }
    }
 public function showPaypal()
 {
     $api_context = PayPalHelper::getApiContext();
     try {
         $params = array('access_token' => PayPalHelper::generateAccessTokenFromRefreshToken(Auth::user()->paypal_key));
         $user = OpenIdUserinfo::getUserinfo($params, $api_context);
     } catch (Exception $ex) {
         print "no pp key";
     }
     /*
     // Create a new instance of Plan object
     $plan = new Plan();
     
     // # Basic Information
     // Fill up the basic information that is required for the plan
     $plan->setName('Welltakeyourmoney')
         ->setDescription('If you register we can take all your money.')
         ->setType('fixed');
     
     $paymentDefinition = new PaymentDefinition();
     
     // The possible values for such setters are mentioned in the setter method documentation.
     // Just open the class file. e.g. lib/PayPal/Api/PaymentDefinition.php and look for setFrequency method.
     // You should be able to see the acceptable values in the comments.
     $paymentDefinition->setName('Regular Payments')
         ->setType('REGULAR')
         ->setFrequency('Month')
         ->setFrequencyInterval("5")
         ->setCycles("12")
         ->setAmount(new Currency(array('value' => 999, 'currency' => 'USD')));
     // ### Create Plan
     $merchantPreferences = new MerchantPreferences();
     
     $merchantPreferences->setReturnUrl(route('auth.dashboard'))
         ->setCancelUrl(route('auth.dashboard'))
         ->setAutoBillAmount("yes")
         ->setInitialFailAmountAction("CONTINUE")
         ->setMaxFailAttempts("0")
         ->setSetupFee(new Currency(array('value' => 9999, 'currency' => 'USD')));
     
     $plan->setPaymentDefinitions(array($paymentDefinition));
     $plan->setMerchantPreferences($merchantPreferences);
     
     $request = clone $plan;
     
     try {
         $output = $plan->create($api_context);
     } catch (PayPal\Exception\PPConnectionException $ex) {
         echo '<pre>';print_r(json_decode($ex->getData()));
         exit(1);
     }
     */
     try {
         $params = array('page_size' => '20');
         $planList = Plan::all($params, $api_context);
     } catch (PayPal\Exception\ConnectionException $ex) {
         echo '<pre>';
         print_r(json_decode($ex->getData()));
         exit(1);
     }
     Log::info($planList);
     try {
         $plan = Plan::get("P-0TA38541GG196850X3XYQ2KI", $api_context);
     } catch (PayPal\Exception\ConnectionException $ex) {
         echo '<pre>';
         print_r(json_decode($ex->getData()));
         exit(1);
     }
     return View::make('dev.paypal', array('output' => $plan));
 }
// # 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);
 }
Example #6
0
 public function getBillingPlan($planId, $apiContext = null)
 {
     if (empty($apiContext)) {
         $apiContext = $this->getApiContext();
     }
     $plan = new Plan();
     return $plan->get($planId, $apiContext);
 }
Example #7
0
 /**
  * Getting all the plans for the user
  * @param paypal api_context
  *
  * @return an array with the plans
  */
 public static function getPlans($api_context)
 {
     // initializing output array
     $out_plans = array();
     try {
         // getting the list of plans
         $params = array('page_size' => '20', 'status' => 'ACTIVE');
         // needs paging !!!!
         $planlist = Plan::all($params, $api_context);
     } catch (PayPal\Exception\PPConnectionException $ex) {
         // error handling
         echo '<pre>';
         print_r(json_decode($ex->getData()));
         exit(1);
     }
     // building up the output array
     foreach ($planlist->getPlans() as $raw_plan) {
         // getting the plan
         $plan = Plan::get($raw_plan->getId(), $api_context);
         // decoding data
         $json_plan = json_decode($plan->toJSON(), true);
         // initializing array to add
         $plan_instance = array();
         // extracting data
         $plan_instance['name'] = $json_plan['name'];
         $plan_instance['interval'] = $json_plan['payment_definitions'][0]['frequency'];
         $plan_instance['interval_count'] = $json_plan['payment_definitions'][0]['frequency_interval'];
         $plan_instance['currency'] = $json_plan['payment_definitions'][0]['amount']['currency'];
         $plan_instance['amount'] = $json_plan['payment_definitions'][0]['amount']['value'] * 100;
         $plan_instance['provider'] = 'paypal';
         // adding to array
         $out_plans[self::generatePlanId($plan)] = $plan_instance;
     }
     // returning object
     return $out_plans;
 }
Example #8
0
 /**
  * Get paypal plan
  * @param $planId
  * @return Plan
  */
 function get($planId)
 {
     return Plan::get($planId, $this->getAdapter()->getApiContext());
 }
Example #9
0
<?php

require __DIR__ . '/../bootstrap.php';
use PayPal\Api\ChargeModel;
use PayPal\Api\Currency;
use PayPal\Api\MerchantPreferences;
use PayPal\Api\PaymentDefinition;
use PayPal\Api\Plan;
// # Get Plan Sample
//
// This sample code demonstrate how you can get a billing plan, as documented here at:
// https://developer.paypal.com/webapps/developer/docs/api/#retrieve-a-plan
// API used: /v1/payments/billing-plans
// Retrieving the Plan object from Create Plan Sample
/** @var Plan $createdPlan */
$plan_id = 'P-2XM09435HG6440939WL5BD4A';
try {
    $plan = Plan::get($plan_id, $apiContext);
} catch (Exception $ex) {
    // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
    ResultPrinter::printError("Retrieved a Plan", "Plan", $plan->getId(), null, $ex);
    exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Retrieved a Plan", "Plan", $plan->getId(), null, $plan);
return $plan;