コード例 #1
0
ファイル: PayPalApi.php プロジェクト: sebardo/ecommerce
 public function createBillingPlan($cartSummary, $productName, $transactionId, $apiContext)
 {
     $billingPlanDefaultValues = $this->getBillingPlanDefaultValues();
     $billingPlan = new Plan();
     $billingPlan->setName('Payment plan for ' . $productName);
     $billingPlan->setDescription($cartSummary->paymentPlanTitle);
     $billingPlan->setType($billingPlanDefaultValues->type);
     $paymentDefinition = new PaymentDefinition();
     $paymentDefinition->setName('Charge for ' . $productName);
     $paymentDefinition->setType('REGULAR');
     $paymentDefinition->setFrequencyInterval($billingPlanDefaultValues->interval);
     $paymentDefinition->setFrequency($billingPlanDefaultValues->frequency);
     $paymentDefinition->setCycles($billingPlanDefaultValues->cycle);
     $amount = new Currency();
     $amount->setCurrency($this->getCurrency());
     $amount->setValue($cartSummary->singleInstallmentCost);
     $paymentDefinition->setAmount($amount);
     $shippingAmount = new Currency();
     $shippingAmount->setCurrency($this->getCurrency());
     // Shipping cost is taken out in the initial payment (setup_fees)
     $shippingAmount->setValue(0);
     //$shippingAmount->setValue($cartSummary->shippingCost);
     $chargeModelShipping = new ChargeModel();
     $chargeModelShipping->setType('SHIPPING');
     $chargeModelShipping->setAmount($shippingAmount);
     $taxAmount = new Currency();
     $taxAmount->setCurrency($this->getCurrency());
     $taxAmount->setValue($cartSummary->vat);
     $chargeModelTax = new ChargeModel();
     $chargeModelTax->setType('TAX');
     $chargeModelTax->setAmount($taxAmount);
     $paymentDefinition->setChargeModels(array($chargeModelShipping, $chargeModelTax));
     $billingPlan->setPaymentDefinitions(array($paymentDefinition));
     $merchantPreferences = new MerchantPreferences();
     $setupFeesAmount = new Currency();
     $setupFeesAmount->setCurrency($this->getCurrency());
     $setupFeesAmount->setValue($cartSummary->firstInstallmentCost);
     /* PayPal just passes a token in the return Url. This token is unique for each request. So pass the transection id in the return Url. */
     $returnUrl = $this->getRecurringExpressPaymentReturnUrl();
     $returnUrl = str_replace(':id', $transactionId, $returnUrl);
     $returnUrl = str_replace(':hash', Om_Model_Abstract::generateRequestHash($transactionId), $returnUrl);
     $merchantPreferences->setSetupFee($setupFeesAmount);
     $merchantPreferences->setCancelUrl($this->getCancelUrl());
     $merchantPreferences->setReturnUrl($returnUrl);
     $merchantPreferences->setMaxFailAttempts($billingPlanDefaultValues->maxFailedBillingAttempts);
     $merchantPreferences->setAutoBillAmount($billingPlanDefaultValues->autoBillAmount);
     $merchantPreferences->setInitialFailAmountAction($billingPlanDefaultValues->initialFailAmountAction);
     $billingPlan->setMerchantPreferences($merchantPreferences);
     return $billingPlan->create($apiContext);
 }