frontend/modules/paypal/controllers/DefaultController.php
/**
     * Start it once. Its create a plan for paypal-subscriptions
     * @return array
     */
Start it once. Its create a plan for paypal-subscriptions
@return array
Start it once . Its create a plan for paypal - subscriptions @return array
public function actionCreatePlans()
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        $neededPlans = [
            'PricePerMonthForLicenseProfessional' => 'MONTH',
            'PricePerYearForLicenseProfessional'  => 'YEAR',
            'PricePerMonthUserForLicenseBusiness' => 'MONTH',
            'PricePerYearUserForLicenseBusiness'  => 'YEAR',
        ];
        $ret = [];
        foreach ($neededPlans as $k=>$v) {
            unset($plan);
            if ($v == 'YEAR') {
                $cost = Preferences::getValueByKey($k) * 12;
            } else {
                $cost = Preferences::getValueByKey($k);
            }
            $plan = $this->paypal->createPlan(
                $k,
                $k,
                $cost,
                'USD',
                $v
            );
            if (is_object($plan) && get_class($plan) == 'PayPal\Api\Plan') {
                $PDS = $plan->getPaymentDefinitions();
                $ret[$k] = [
                    'PlanId' => $plan->getId(),
                    'PaymentDefinitionId' => $PDS[0]->getId(),
                    'PaymentDefinitionCost' => $PDS[0]->getAmount()->getValue(),
                ];
                Preferences::setValueByKey("PP-{$k}", Json::encode($ret[$k]));
            }
        }
        return $ret;
    }
public function actionCreatePlans ( ) { Yii :: $ app -> response -> format = Response :: FORMAT_JSON ; $ neededPlans = [ 'PricePerMonthForLicenseProfessional' => 'MONTH' , 'PricePerYearForLicenseProfessional' => 'YEAR' , 'PricePerMonthUserForLicenseBusiness' => 'MONTH' , 'PricePerYearUserForLicenseBusiness' => 'YEAR' , ] ; $ ret = [ ] ; foreach ( $ neededPlans as $ k => $ v ) { unset ( $ plan ) ; if ( $ v == 'YEAR' ) { $ cost = Preferences :: getValueByKey ( $ k ) * 12 ; } else { $ cost = Preferences :: getValueByKey ( $ k ) ; } $ plan = $ this -> paypal -> createPlan ( $ k , $ k , $ cost , 'USD' , $ v ) ; if ( is_object ( $ plan ) && get_class ( $ plan ) == 'PayPal\Api\Plan' ) { $ PDS = $ plan -> getPaymentDefinitions ( ) ; $ ret [ $ k ] = [ 'PlanId' => $ plan -> getId ( ) , 'PaymentDefinitionId' => $ PDS [ 0 ] -> getId ( ) , 'PaymentDefinitionCost' => $ PDS [ 0 ] -> getAmount ( ) -> getValue ( ) , ] ; Preferences :: setValueByKey ( " PP- { $ k } " , Json :: encode ( $ ret [ $ k ] ) ) ; } } return $ ret ; }
Start it once.
Start it once .
//var_dump($plan);exit; //var_dump($PDS[0]->getId()); exit;