Ejemplo n.º 1
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()];
        }
    }
Ejemplo n.º 2
0
 function get($params = [])
 {
     try {
         return $planList = Plan::all($params, $this->getAdapter()->getApiContext());
     } catch (\Exception $ex) {
         //@todo add logging
     }
 }
Ejemplo n.º 3
0
 /**
  * Create billing agreement with paypal
  * @param $createdPlan
  * @param $agreementName
  * @param $agreementDescription
  * @param string $startTime
  * @return null|string Redirect url
  */
 function create($createdPlan, $agreementName, $agreementDescription, $startTime = '')
 {
     if (empty($startTime)) {
         $time = time() + 30 * (24 * 3600);
         $startTime = date('Y-m-d\\TH:i:s\\Z', $time);
     }
     $agreement = new Agreement();
     $agreement->setName($agreementName)->setDescription($agreementDescription)->setStartDate($startTime);
     // Add Plan ID
     $plan = new Plan();
     $plan->setId($createdPlan['id']);
     $agreement->setPlan($plan);
     // Add Payer
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $agreement->setPayer($payer);
     // Please note that as the agreement has not yet activated, we wont be receiving the ID just yet.
     $agreement = $agreement->create($this->getAdapter()->getApiContext());
     // ### Get redirect url
     // The API response provides the url that you must redirect
     // the buyer to. Retrieve the url from the $agreement->getApprovalLink()
     // method
     return $agreement->getApprovalLink();
 }
Ejemplo n.º 4
0
 /**
  * Create billing plan at paypal
  *
  * @param $name
  * @param $description
  * @param $amount
  * @param string $returnUrl
  * @param string $returnCancel
  * @param int $setupFee
  * @param bool $isTrial
  * @param string $currency
  * @param string $planType
  * @param string $definitionName
  * @param string $definitionType
  * @param string $definitionFrequency
  * @param string $definitionFrequencyInterval
  * @param string $definitionCycles
  * @param string $trialDefinitionName
  * @param string $trialDefinitionType
  * @param string $trialDefinitionFrequency
  * @param string $trialDefinitionFrequencyInterval
  * @param string $trialDefinitionCycles
  * @param string $trialDefinitionAmount
  * @return string
  */
 function create($name, $description, $amount, $returnUrl = '', $returnCancel = '', $setupFee = 0, $isTrial = false, $currency = 'USD', $planType = 'fixed', $definitionName = 'Regular Payments', $definitionType = 'REGULAR', $definitionFrequency = 'Month', $definitionFrequencyInterval = '1', $definitionCycles = '12', $trialDefinitionName = 'Trial Period', $trialDefinitionType = 'TRIAL', $trialDefinitionFrequency = '0', $trialDefinitionFrequencyInterval = '0', $trialDefinitionCycles = '0', $trialDefinitionAmount = '0')
 {
     $plan = new Plan();
     $plan->setName($name)->setDescription($description)->setType($planType);
     $paymentDefinition = new PaymentDefinition();
     $paymentDefinition->setName($definitionName)->setType($definitionType)->setFrequency($definitionFrequency)->setFrequencyInterval($definitionFrequencyInterval)->setCycles($definitionCycles)->setAmount(new Currency(array('value' => $amount, 'currency' => $currency)));
     $plan->setPaymentDefinitions(array($paymentDefinition));
     if ($isTrial) {
         $paymentDefinitionTrial = new PaymentDefinition();
         $paymentDefinitionTrial->setName($trialDefinitionName)->setType($trialDefinitionType)->setFrequency($trialDefinitionFrequency)->setFrequencyInterval($trialDefinitionFrequencyInterval)->setCycles($trialDefinitionCycles)->setAmount(new Currency(array('value' => $trialDefinitionAmount, 'currency' => $currency)));
         $plan->addPaymentDefinition($paymentDefinitionTrial);
     }
     $merchantPreferences = new MerchantPreferences();
     $merchantPreferences->setReturnUrl($returnUrl)->setCancelUrl($returnCancel)->setAutoBillAmount("yes")->setInitialFailAmountAction("CONTINUE")->setMaxFailAttempts("0")->setSetupFee(new Currency(array('value' => $setupFee, 'currency' => $currency)));
     $plan->setPaymentDefinitions(array($paymentDefinition));
     $plan->setMerchantPreferences($merchantPreferences);
     $result = $plan->create($this->getAdapter()->getApiContext());
     if ($result) {
         return ['plan' => $result, 'id' => $result->getId(), 'state' => $result->getState(), 'created' => $result->getCreateTime()];
     }
     return $result;
 }
Ejemplo n.º 5
0
 /**
  * Retrieve the details for a particular billing plan by passing the billing plan ID to the request URI.
  *
  * @param string $planId
  * @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 Plan
  */
 public static function get($planId, $apiContext = null, $restCall = null)
 {
     ArgumentValidator::validate($planId, 'planId');
     $payLoad = "";
     $json = self::executeCall("/v1/payments/billing-plans/{$planId}", "GET", $payLoad, null, $apiContext, $restCall);
     $ret = new Plan();
     $ret->fromJson($json);
     return $ret;
 }
Ejemplo n.º 6
0
 public function createBillingAgreement($planId, $shippingAddress, $billingAddress, $productName, $cartSummary, $cardDetails, $apiContext)
 {
     $billingPlanDefaultValues = $this->getBillingPlanDefaultValues();
     $billingAgreement = new Agreement();
     $billingAgreement->setName('Billing Agreement For ' . $productName);
     $billingAgreement->setDescription($cartSummary->paymentPlanTitle);
     $startDate = new Zend_Date();
     $startDate->addDay($billingPlanDefaultValues->startDateInterval);
     $billingAgreement->setStartDate($startDate->get(Zend_Date::ISO_8601));
     $payerInfo = new PayerInfo();
     $payerInfo->setFirstName($billingAddress->firstname);
     $payerInfo->setLastName($billingAddress->lastname);
     $payerInfo->setEmail($billingAddress->emailAddress);
     /* Fields not supported yet */
     //$payerInfo->setEmail($cart->address->billing['billing_email']);
     //$payerInfo->setPhone($cart->address->billing['billing_contactNo']);
     /* Get a MALFORMED_REQUEST error when using this field */
     //$payerInfo->setCountryCode($cart->address->billing['billing_countryCode']);
     $cardName = $cardDetails->cardName;
     $cardNumber = $cardDetails->cardNumber;
     $cardType = strtolower($cardDetails->cardType);
     $cardExpiryMonth = $cardDetails->cardExpiryMonth;
     $cardExpiryYear = $cardDetails->cardExpiryYear;
     $cardSecurityCode = $cardDetails->cardSecurityCode;
     $nameParser = new Om_Model_Name();
     $name = $nameParser->parse_name($cardName);
     $card = new CreditCard();
     $card->setType($cardType);
     $card->setNumber($cardNumber);
     $card->setExpireMonth($cardExpiryMonth);
     $card->setExpireYear($cardExpiryYear);
     $card->setCvv2($cardSecurityCode);
     $card->setFirstName($name['fname']);
     $card->setLastName($name['lname']);
     $fundingInstrument = new FundingInstrument();
     $fundingInstrument->setCreditCard($card);
     $payer = new Payer();
     $payer->setPaymentMethod("credit_card");
     $payer->setFundingInstruments(array($fundingInstrument));
     $payer->setPayerInfo($payerInfo);
     $billingAgreement->setPayer($payer);
     $shippingAddressPayPal = new Address();
     $shippingAddressPayPal->setLine1($shippingAddress->addressLine1);
     $shippingAddressPayPal->setLine2($shippingAddress->addressLine2 . ' ' . $shippingAddress->addressLine3);
     $shippingAddressPayPal->setCity($shippingAddress->city);
     $shippingAddressPayPal->setCountryCode($shippingAddress->getCountry()->code);
     $shippingAddressPayPal->setPostalCode($shippingAddress->postcode);
     $shippingAddressPayPal->setState($shippingAddress->county);
     $shippingAddressPayPal->setPhone($shippingAddress->contactNumber);
     $billingAgreement->setShippingAddress($shippingAddressPayPal);
     $plan = new Plan();
     $plan->setId($planId);
     $billingAgreement->setPlan($plan);
     return $billingAgreement->create($apiContext);
 }
Ejemplo n.º 7
0
 /**
  * @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);
 }
Ejemplo n.º 8
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;
 }
Ejemplo n.º 9
0
 /**
  * Get paypal plan
  * @param $planId
  * @return Plan
  */
 function get($planId)
 {
     return Plan::get($planId, $this->getAdapter()->getApiContext());
 }
Ejemplo n.º 10
0
<?php

// # Create Plan Sample
//
// This sample code demonstrate how you can create a billing plan, as documented here at:
// https://developer.paypal.com/webapps/developer/docs/api/#create-a-plan
// API used: /v1/payments/billing-plans
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\ChargeModel;
use PayPal\Api\Currency;
use PayPal\Api\MerchantPreferences;
use PayPal\Api\PaymentDefinition;
use PayPal\Api\Plan;
// 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('ThinkThinly monthly subscription 0 dollar')->setDescription('ThinkThinly monthly subscription 0 dollar')->setType('fixed');
// # Payment definitions for this billing plan.
$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("1")->setCycles("12")->setAmount(new Currency(array('value' => 4.99, 'currency' => 'USD')));
// # Trial Payment definitions for this billing plan.
$trialPaymentDefinition = 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.
$trialPaymentDefinition->setName('Regular Payments')->setType('TRIAL')->setFrequency('Month')->setFrequencyInterval("1")->setCycles("1200")->setAmount(new Currency(array('value' => 0, 'currency' => 'USD')));
// Charge Models
Ejemplo n.º 11
0
 /**
  * @param $createdPlan
  * @return Plan
  */
 function delete(Plan $createdPlan)
 {
     return $createdPlan->delete($this->getAdapter()->getApiContext());
 }
Ejemplo n.º 12
0
<?php

// # Create Plan Sample
//
// This sample code demonstrate how you can create a billing plan, as documented here at:
// https://developer.paypal.com/webapps/developer/docs/api/#create-a-plan
// API used: /v1/payments/billing-plans
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\ChargeModel;
use PayPal\Api\Currency;
use PayPal\Api\MerchantPreferences;
use PayPal\Api\PaymentDefinition;
use PayPal\Api\Plan;
// 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('T-Shirt of the Month Club Plan')->setDescription('Template creation.')->setType('fixed');
// # Payment definitions for this billing plan.
$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("2")->setCycles("12")->setAmount(new Currency(array('value' => 100, 'currency' => 'USD')));
// Charge Models
$chargeModel = new ChargeModel();
$chargeModel->setType('SHIPPING')->setAmount(new Currency(array('value' => 10, 'currency' => 'USD')));
$paymentDefinition->setChargeModels(array($chargeModel));
$merchantPreferences = new MerchantPreferences();
$baseUrl = getBaseUrl();
// ReturnURL and CancelURL are not required and used when creating billing agreement with payment_method as "credit_card".
Ejemplo n.º 13
0
 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));
 }
Ejemplo n.º 14
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;
// # 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;
    $plan_id = 'P-2XM09435HG6440939WL5BD4A';
    //    $plan_id = 'P-2XM09435HG6440939WL5BD4A';//old plan
    $agree_desc = 'ThinkThinly monthly subscription';
}
use PayPal\Api\Agreement;
use PayPal\Api\Payer;
use PayPal\Api\Plan;
use PayPal\Api\ShippingAddress;
$agreement = new Agreement();
$now = new DateTime();
$now->add(DateInterval::createFromDateString('10 hour'));
$agreement->setName('Base Agreement')->setDescription($agree_desc)->setStartDate($now->format('Y-m-d') . 'T' . $now->format('G:i:s') . 'Z');
//    ->setStartDate('2019-06-17T9:45:04Z');
// Add Plan ID
// Please note that the plan Id should be only set in this case.
$plan = new Plan();
$plan->setId($plan_id);
$agreement->setPlan($plan);
// Add Payer
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$agreement->setPayer($payer);
$agreement->setDescription($agree_desc . ". ID: {$user_id}");
// Add Shipping Address
//$shippingAddress = new ShippingAddress();
//$shippingAddress->setLine1('111 First Street')
//    ->setCity('Saratoga')
//    ->setState('CA')
//    ->setPostalCode('95070')
//    ->setCountryCode('US');
//$agreement->setShippingAddress($shippingAddress);
 /**
  * @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);
 }
                "credit_card": {
                    "type": "visa",
                    "number": "4417119669820331",
                    "expire_month": "12",
                    "expire_year": "2017",
                    "cvv2": "128"
                }
            }
        ]
    }
}*/
$agreement = new Agreement();
$agreement->setName('DPRP')->setDescription('Payment with credit Card')->setStartDate('2015-06-17T9:45:04Z');
// Add Plan ID
// Please note that the plan Id should be only set in this case.
$plan = new Plan();
$plan->setId($createdPlan->getId());
$agreement->setPlan($plan);
// Add Payer
$payer = new Payer();
$payer->setPaymentMethod('credit_card')->setPayerInfo(new PayerInfo(array('email' => '*****@*****.**')));
// Add Credit Card to Funding Instruments
$creditCard = new CreditCard();
$creditCard->setType('visa')->setNumber('4491759698858890')->setExpireMonth('12')->setExpireYear('2017')->setCvv2('128');
$fundingInstrument = new FundingInstrument();
$fundingInstrument->setCreditCard($creditCard);
$payer->setFundingInstruments(array($fundingInstrument));
//Add Payer to Agreement
$agreement->setPayer($payer);
// Add Shipping Address
$shippingAddress = new ShippingAddress();
Ejemplo n.º 19
-1
<?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;