Ejemplo n.º 1
0
 /**
  * Add a simple product line, with values similar to the old (non-XML) basket.
  * This adds a product line array to the lines array. The more complex lines with other details
  * will involve adding a line as an object. Simple lines and complex lines can be freely mixed.
  */
 public function addSimpleLine($description, $quantity, $unit_net, $unit_tax = 0, $unit_gross = null, $line_gross = null)
 {
     // Fill in some gaps, if required.
     if (!isset($unit_gross)) {
         $unit_gross = $unit_net + $unit_tax;
     }
     if (!isset($line_gross)) {
         $line_gross = $unit_gross * $quantity;
     }
     $this->lines[] = array('description' => $description, 'quantity' => $quantity, 'unitNetAmount' => Helper::formatAmount($unit_net, $this->currency), 'unitTaxAmount' => Helper::formatAmount($unit_tax, $this->currency), 'unitGrossAmount' => Helper::formatAmount($unit_gross, $this->currency), 'totalGrossAmount' => Helper::formatAmount($line_gross, $this->currency));
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Add a fixed amount surcharge.
  * Set the currency *before* adding a fixed amount.
  */
 public function addFixed($payment_type, $fixed)
 {
     $this->surcharges[]['surcharge'] = array('paymentType' => strtoupper($payment_type), 'fixed' => Helper::formatAmount($fixed, $this->currency));
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Set the ammount and currency.
  */
 public function setAmount($amount, $currency = 'GBP')
 {
     // Set the currency first, before we start formatting amounts.
     $this->setCurrency($currency);
     // Some minimal validation.
     $currency = strtoupper($currency);
     $this->setField('Amount', Helper::formatAmount($amount, $this->currency));
     $this->setField('Currency', $currency);
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Return the product line as a nested array in a structure that mimics
  * the XML format that SagePay expects.
  */
 public function toArray()
 {
     $structure = array();
     // A mix of optional and mandatory fields.
     // The order is important to prevent the basket being rejected as having and
     // "invalid format".
     $structure['description'] = $this->description;
     if (isset($this->productSku)) {
         $structure['productSku'] = $this->productSku;
     }
     if (isset($this->productCode)) {
         $structure['productCode'] = $this->productCode;
     }
     $structure['quantity'] = $this->quantity;
     $structure['unitNetAmount'] = Helper::formatAmount($this->unitNetAmount, $this->currency);
     $structure['unitTaxAmount'] = Helper::formatAmount($this->unitTaxAmount, $this->currency);
     $structure['unitGrossAmount'] = Helper::formatAmount($this->unitGrossAmount, $this->currency);
     $structure['totalGrossAmount'] = Helper::formatAmount($this->totalGrossAmount, $this->currency);
     // Note: the SagePay documentation says that accented (i.e. extended ASCII)
     // characters are allowed in the recipient's name. This does, however, result
     // in an "invalid basket format" if you do, at least at the tine of writing.
     // The API may be buggy, or the documenation may be wrong. It is not clear which.
     if (isset($this->recipientFName)) {
         $structure['recipientFName'] = $this->recipientFName;
     }
     if (isset($this->recipientLName)) {
         $structure['recipientLName'] = $this->recipientLName;
     }
     if (isset($this->recipientMName)) {
         $structure['recipientMName'] = $this->recipientMName;
     }
     if (isset($this->recipientSal)) {
         $structure['recipientSal'] = $this->recipientSal;
     }
     if (isset($this->recipientEmail)) {
         $structure['recipientEmail'] = $this->recipientEmail;
     }
     if (isset($this->recipientPhone)) {
         $structure['recipientPhone'] = $this->recipientPhone;
     }
     if (isset($this->recipientAdd1)) {
         $structure['recipientAdd1'] = $this->recipientAdd1;
     }
     if (isset($this->recipientAdd2)) {
         $structure['recipientAdd2'] = $this->recipientAdd2;
     }
     if (isset($this->recipientCity)) {
         $structure['recipientCity'] = $this->recipientCity;
     }
     if (isset($this->recipientState)) {
         $structure['recipientState'] = $this->recipientState;
     }
     if (isset($this->recipientCountry)) {
         $structure['recipientCountry'] = $this->recipientCountry;
     }
     if (isset($this->recipientPostCode)) {
         $structure['recipientPostCode'] = $this->recipientPostCode;
     }
     if (isset($this->itemShipNo)) {
         $structure['itemShipNo'] = $this->itemShipNo;
     }
     if (isset($this->itemGiftMsg)) {
         $structure['itemGiftMsg'] = $this->itemGiftMsg;
     }
     return array('item' => $structure);
 }