/** * @param array $attributes * @return PaytrailAddress */ public static function create(array $attributes) { $model = new PaytrailAddress(); $model->attributes = $attributes; if (!$model->save()) { throw new CException('Failed to save paytrail address.'); } return $model; }
/** * @param PaymentTransaction $transaction */ public function prepareTransaction(PaymentTransaction $transaction) { $attributes = array(); foreach (array('success', 'failure', 'notification', 'pending') as $attribute) { if (isset($this->{$attribute . 'Route'})) { $attributes[$attribute . 'Url'] = Yii::app()->createAbsoluteUrl($this->{$attribute . 'Route'}); } } $urlset = PaytrailUrlset::create($attributes); $address = PaytrailAddress::create(array('streetAddress' => $transaction->shippingContact->streetAddress, 'postalCode' => $transaction->shippingContact->postalCode, 'postOffice' => $transaction->shippingContact->postOffice, 'countryCode' => $this->normalizeCountry($transaction->shippingContact->countryCode))); $contact = PaytrailContact::create(array('firstName' => $transaction->shippingContact->firstName, 'lastName' => $transaction->shippingContact->lastName, 'email' => $transaction->shippingContact->email, 'phoneNumber' => $transaction->shippingContact->phoneNumber, 'mobileNumber' => $transaction->shippingContact->mobileNumber, 'companyName' => $transaction->shippingContact->companyName, 'addressId' => $address->id)); $payment = PaytrailPayment::create(array('orderNumber' => $transaction->orderIdentifier, 'referenceNumber' => $transaction->referenceNumber, 'description' => $transaction->description, 'contactId' => $contact->id, 'urlsetId' => $urlset->id, 'locale' => $this->normalizeLocale($transaction->locale))); foreach ($transaction->items as $item) { PaytrailProduct::create(array('paymentId' => $payment->id, 'title' => $item->description, 'code' => $item->code, 'quantity' => (double) $item->quantity, 'price' => $item->price, 'vat' => $item->vat, 'discount' => $item->discount, 'type' => Product::TYPE_NORMAL)); } $this->_payment = $payment; }