Пример #1
0
 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);
 }
Пример #2
0
 /**
  * @depends testSerializationDeserialization
  * @param Currency $obj
  */
 public function testGetters($obj)
 {
     $this->assertEquals($obj->getCurrency(), "TestSample");
     $this->assertEquals($obj->getValue(), "12.34");
 }
 function get_presentment($amount, $currency, $country_iso, $single = false)
 {
     $presentment_array = array();
     // auth
     $apiContext = $this->apiContext();
     // transaction Amount
     $transactionAmount = new Currency();
     $transactionAmount->setCurrencyCode($currency)->setValue($amount);
     // presentment
     $presentment = new Presentment();
     $presentment->setFinancingCountryCode($country_iso)->setTransactionAmount($transactionAmount);
     try {
         $presentment->create($apiContext);
         $financing_options = $presentment->getFinancingOptions();
         foreach ($financing_options as $financing_option) {
             $qualifying_financing_options = $financing_option->getQualifyingFinancingOptions();
             if (count($qualifying_financing_options) > 0) {
                 foreach ($qualifying_financing_options as $qualifying_financing_option) {
                     $credit_financing = $qualifying_financing_option->getCreditFinancing();
                     if ($credit_financing->getEnabled() === true && (string) $presentment->getTransactionAmount()->getValue() >= (string) $qualifying_financing_option->getMinAmount()->getValue()) {
                         $presentment_array[] = array('mark' => false, 'financing_code' => $credit_financing->getFinancingCode(), 'apr' => $credit_financing->getApr(), 'nominal_rate' => $credit_financing->getNominalRate(), 'term' => $credit_financing->getTerm(), 'country_code' => $credit_financing->getCountryCode(), 'credit_type' => $credit_financing->getCreditType(), 'vendor_financing_id' => $credit_financing->getVendorFinancingId(), 'monthly_percentage_rate' => $qualifying_financing_option->getMonthlyPercentageRate(), 'currency_code' => $qualifying_financing_option->getMonthlyPayment()->getCurrencyCode(), 'min_amount' => $qualifying_financing_option->getMinAmount()->getValue(), 'monthly_payment_plain' => $qualifying_financing_option->getMonthlyPayment()->getValue(), 'monthly_payment' => $this->format_price_currency($qualifying_financing_option->getMonthlyPayment()->getValue()), 'total_cost' => $this->format_price_currency($qualifying_financing_option->getTotalCost()->getValue()), 'total_interest' => $this->format_price_currency($qualifying_financing_option->getTotalInterest()->getValue()));
                     }
                 }
             }
         }
     } catch (Exception $ex) {
         $this->LoggingManager->log(print_r($ex, true), 'DEBUG');
     }
     if (count($presentment_array) > 0) {
         $presentment_array = $this->validate_presentment($presentment_array, $single);
     }
     return $presentment_array;
 }