public function getNVPRequest() { $request = $this->collection->getAllValues(); if ($this->shippingAddress != null) { $request = array_merge($request, $this->shippingAddress->getNVPArray()); } if ($this->billingPeriod != null) { $request = array_merge($request, $this->billingPeriod->getNVPArray()); } if ($this->creditCard != null) { $request = array_merge($request, $this->creditCard->getNVPArray()); } if ($this->payerInformation != null) { $request = array_merge($request, $this->payerInformation->getNVPArray()); } if ($this->address != null) { $request = array_merge($request, $this->address->getNVPArray()); } return $request; }
/** * Calling object needs to prepend 'PAYMENTREQUEST_n_', if value is an * array then needs to prepend 'L_PAYMENTREQUEST_n_...m' * * @return array */ public function getNVPArray() { /* response */ if (!$this->request) { $response = $this->collection->getAllValues(); if ($this->address != null) { $response = array_merge($response, $this->address->getNVPArray()); } if ($this->seller != null) { $response = array_merge($response, $this->seller->getNVPArray()); } foreach ($this->items as $index => $value) { $response[$index] = $value->getNVPArray(); } return $response; } /* request */ $response = array(); /* total amount of all items */ $itemAmount = 0; /* total tax of all items */ $taxAmount = 0; /* items in this payment */ $items = array(); /* add amount and tax from all items and create keys for nvp */ foreach ($this->items as $index => $item) { foreach ($item->getNVPArray() as $key => $value) { if ($key == 'AMT') { $itemAmount += $value; } if ($key == 'TAXAMT') { $taxAmount += $value; } $items[$index][$key] = $value; } } if ($itemAmount > 0) { $response['ITEMAMT'] = $itemAmount; } if ($taxAmount > 0) { $response['TAXAMT'] = $taxAmount; } /* add everything to the final amount - AMT */ $response['AMT'] = $itemAmount + $taxAmount; if (isset($this->nvpRequest['SHIPPINGAMT'])) { $respone['AMT'] += $this->nvpRequest['SHIPPINGAMT']; if (isset($this->nvpRequest['SHIPDISCAMT'])) { $respone['AMT'] -= $this->nvpRequest['SHIPDISCAMT']; } } if (isset($this->nvpRequest['INSURANCEAMT'])) { $response['AMT'] += $this->nvpRequest['INSURANCEAMT']; } if (isset($this->nvpRequest['HANDLINGAMT'])) { $response['AMT'] += $this->nvpRequest['HANDLINGAMT']; } /* add items as an array */ $response['items'] = $items; /* merge nvp string with the values autogenarated from items */ return array_merge($this->collection->getAllValues(), $response); }