function get($params = []) { try { return $planList = Plan::all($params, $this->getAdapter()->getApiContext()); } catch (\Exception $ex) { //@todo add logging } }
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)); }
/** * @depends testGet * @param $plan Plan */ public function testGetList($plan) { $result = Plan::all(array('page_size' => '20', 'total_required' => 'yes'), $this->apiContext, $this->mockPayPalRestCall); $this->assertNotNull($result); $totalPages = $result->getTotalPages(); $found = false; $foundObject = null; do { foreach ($result->getPlans() as $obj) { if ($obj->getId() == $plan->getId()) { $found = true; $foundObject = $obj; break; } } if (!$found) { $result = Plan::all(array('page' => --$totalPages, 'page_size' => '20', 'total_required' => 'yes'), $this->apiContext, $this->mockPayPalRestCall); } } while ($totalPages > 0 && $found == false); $this->assertTrue($found, "The Created Plan was not found in the get list"); $this->assertEquals($plan->getId(), $foundObject->getId()); }
/** * @dataProvider mockProvider * @param Plan $obj */ public function testList($obj, $mockApiContext) { $mockPayPalRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock(); $mockPayPalRestCall->expects($this->any())->method('execute')->will($this->returnValue(PlanListTest::getJson())); $params = ParamsTest::getObject(); $result = $obj->all($params, $mockApiContext, $mockPayPalRestCall); $this->assertNotNull($result); }
/** * 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; }
<?php // # Get List of Plan Sample // // This sample code demonstrate how you can get a list of billing plan, as documented here at: // https://developer.paypal.com/webapps/developer/docs/api/#list-plans // API used: /v1/payments/billing-plans // Retrieving the Plan object from Create Plan Sample to demonstrate the List /** @var Plan $createdPlan */ $createdPlan = (require 'CreatePlan.php'); use PayPal\Api\Plan; try { // Get the list of all plans // You can modify different params to change the return list. // The explanation about each pagination information could be found here // at https://developer.paypal.com/webapps/developer/docs/api/#list-plans $params = array('page_size' => '2'); $planList = Plan::all($params, $apiContext); } catch (Exception $ex) { // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printError("List of Plans", "Plan", null, $params, $ex); exit(1); } // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printResult("List of Plans", "Plan", null, $params, $planList); return $planList;