Version Notes
Fix renaming issues between alpha and first stable
Download this release
Release Info
Developer | Nicklas Møller |
Extension | Nicklasmoeller_BillysBilling |
Version | 0.2.1 |
Comparing to | |
See all releases |
Code changes from version 0.2.0 to 0.2.1
- app/code/community/Nicklasmoeller/Billysbilling/Helper/Data.php +25 -0
- app/code/community/Nicklasmoeller/Billysbilling/Model/Abstract.php +23 -0
- app/code/community/Nicklasmoeller/Billysbilling/Model/Client.php +59 -0
- app/code/community/Nicklasmoeller/Billysbilling/Model/Contact.php +77 -0
- app/code/community/Nicklasmoeller/Billysbilling/Model/Country.php +48 -0
- app/code/community/Nicklasmoeller/Billysbilling/Model/Currency.php +34 -0
- app/code/community/Nicklasmoeller/Billysbilling/Model/Invoice.php +119 -0
- app/code/community/Nicklasmoeller/Billysbilling/Model/Observer.php +50 -0
- app/code/community/Nicklasmoeller/Billysbilling/Model/Organization.php +32 -0
- app/code/community/Nicklasmoeller/Billysbilling/Model/Product.php +71 -0
- app/code/community/Nicklasmoeller/Billysbilling/Model/Shipment.php +76 -0
- app/code/community/Nicklasmoeller/Billysbilling/etc/adminhtml.xml +26 -0
- app/code/community/Nicklasmoeller/Billysbilling/etc/config.xml +50 -0
- app/code/community/Nicklasmoeller/Billysbilling/etc/system.xml +54 -0
- app/etc/modules/Nicklasmoeller_Billysbilling.xml +9 -0
- package.xml +5 -5
app/code/community/Nicklasmoeller/Billysbilling/Helper/Data.php
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Nicklasmoeller_Billysbilling_Helper_Data
|
5 |
+
*
|
6 |
+
* @author Nicklas Møller <hello@nicklasmoeller.com>
|
7 |
+
* @version 0.2.0
|
8 |
+
*/
|
9 |
+
class Nicklasmoeller_Billysbilling_Helper_Data extends Mage_Core_Helper_Abstract {
|
10 |
+
/**
|
11 |
+
* @return bool
|
12 |
+
*/
|
13 |
+
public function isEnabled()
|
14 |
+
{
|
15 |
+
return (boolean) Mage::getStoreConfig('billysbilling/settings/enabled');
|
16 |
+
}
|
17 |
+
|
18 |
+
/**
|
19 |
+
* @return bool
|
20 |
+
*/
|
21 |
+
public function isApiKeySet()
|
22 |
+
{
|
23 |
+
return (boolean) Mage::getStoreConfig('billysbilling/api/key');
|
24 |
+
}
|
25 |
+
}
|
app/code/community/Nicklasmoeller/Billysbilling/Model/Abstract.php
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Abstract class Nicklasmoeller_Billysbilling_Model_Abstract
|
5 |
+
*
|
6 |
+
* @author Nicklas Møller <hello@nicklasmoeller.com>
|
7 |
+
* @version 0.2.0
|
8 |
+
*/
|
9 |
+
abstract class Nicklasmoeller_Billysbilling_Model_Abstract extends Mage_Core_Model_Abstract
|
10 |
+
{
|
11 |
+
/**
|
12 |
+
* @var $client
|
13 |
+
*/
|
14 |
+
public $client;
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Instantiate the client
|
18 |
+
*/
|
19 |
+
public function __construct()
|
20 |
+
{
|
21 |
+
$this->client = Mage::getModel('billysbilling/client');
|
22 |
+
}
|
23 |
+
}
|
app/code/community/Nicklasmoeller/Billysbilling/Model/Client.php
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Nicklasmoeller_Billysbilling_Model_Client
|
5 |
+
*
|
6 |
+
* @author Nicklas Møller <hello@nicklasmoeller.com>
|
7 |
+
* @version 0.2.0
|
8 |
+
*/
|
9 |
+
class Nicklasmoeller_Billysbilling_Model_Client
|
10 |
+
{
|
11 |
+
/**
|
12 |
+
* @var
|
13 |
+
*/
|
14 |
+
private $key;
|
15 |
+
|
16 |
+
/**
|
17 |
+
* @var string
|
18 |
+
*/
|
19 |
+
private $uri = "https://api.billysbilling.com/v2";
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Instantiate the api key
|
23 |
+
*/
|
24 |
+
public function __construct()
|
25 |
+
{
|
26 |
+
$this->key = Mage::getStoreConfig('billysbilling/api/key');
|
27 |
+
}
|
28 |
+
|
29 |
+
/**
|
30 |
+
* @param $method
|
31 |
+
* @param $endpoint
|
32 |
+
* @param null|array $body
|
33 |
+
*
|
34 |
+
* @return object
|
35 |
+
*/
|
36 |
+
public function request($method, $endpoint, $body = null)
|
37 |
+
{
|
38 |
+
$headers = ["X-Access-Token: " . $this->key];
|
39 |
+
$ch = curl_init($this->uri . $endpoint);
|
40 |
+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
41 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
42 |
+
|
43 |
+
if ($body) {
|
44 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
|
45 |
+
$headers[] = "Content-Type: application/json";
|
46 |
+
}
|
47 |
+
|
48 |
+
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
49 |
+
|
50 |
+
$response = curl_exec($ch);
|
51 |
+
$body = json_decode($response);
|
52 |
+
$info = curl_getinfo($ch);
|
53 |
+
|
54 |
+
return (object) [
|
55 |
+
'status' => $info['http_code'],
|
56 |
+
'body' => $body
|
57 |
+
];
|
58 |
+
}
|
59 |
+
}
|
app/code/community/Nicklasmoeller/Billysbilling/Model/Contact.php
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Nicklasmoeller_Billysbilling_Model_Contact
|
5 |
+
*
|
6 |
+
* @author Nicklas Møller <hello@nicklasmoeller.com>
|
7 |
+
* @version 0.2.0
|
8 |
+
*/
|
9 |
+
class Nicklasmoeller_Billysbilling_Model_Contact extends Nicklasmoeller_Billysbilling_Model_Abstract
|
10 |
+
{
|
11 |
+
protected $customer;
|
12 |
+
|
13 |
+
/**
|
14 |
+
* @param $billingAddress
|
15 |
+
*
|
16 |
+
* @return bool|mixed
|
17 |
+
*/
|
18 |
+
public function getCustomer($billingAddress)
|
19 |
+
{
|
20 |
+
if ($this->customer) {
|
21 |
+
return $this->customer;
|
22 |
+
}
|
23 |
+
|
24 |
+
$res = $this->client->request("GET", "/contacts?contactNo=" . $billingAddress->getCustomerId());
|
25 |
+
|
26 |
+
if ($res->body->meta->paging->total > 0) {
|
27 |
+
$this->customer = $res->body->contacts[0];
|
28 |
+
|
29 |
+
return $this->customer;
|
30 |
+
}
|
31 |
+
|
32 |
+
$contact = $this->buildCustomer($billingAddress);
|
33 |
+
|
34 |
+
$res = $this->client->request("POST", "/contacts", array(
|
35 |
+
'contact' => $contact
|
36 |
+
));
|
37 |
+
|
38 |
+
if ($res->status !== 200) {
|
39 |
+
return false;
|
40 |
+
}
|
41 |
+
|
42 |
+
$this->customer = $res->body->contacts[0];
|
43 |
+
|
44 |
+
return $this->customer;
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* @param $billingAddress
|
49 |
+
*
|
50 |
+
* @return mixed
|
51 |
+
*/
|
52 |
+
public function buildCustomer($billingAddress)
|
53 |
+
{
|
54 |
+
$contact = new stdClass();
|
55 |
+
|
56 |
+
$contact->organizationId = Mage::getSingleton('billysbilling/organization')->getOrganizationId();
|
57 |
+
$contact->contactNo = $billingAddress->getCustomerId();
|
58 |
+
$contact->countryId = Mage::getSingleton('billysbilling/country')->getCountry($billingAddress->getCountryId());
|
59 |
+
$contact->zipcodeText = $billingAddress->getPostcode();
|
60 |
+
$contact->stateText = $billingAddress->getRegion();
|
61 |
+
$contact->cityText = $billingAddress->getCity();
|
62 |
+
$contact->street = $billingAddress->getStreetFull();
|
63 |
+
$contact->registrationNo = $billingAddress->getVatId();
|
64 |
+
$contact->phone = $billingAddress->getTelephone();
|
65 |
+
$contact->isCustomer = true;
|
66 |
+
|
67 |
+
if ($billingAddress->getCompany()) {
|
68 |
+
$contact->type = 'company';
|
69 |
+
$contact->name = $billingAddress->getCompany();
|
70 |
+
} else {
|
71 |
+
$contact->type = 'person';
|
72 |
+
$contact->name = $billingAddress->getName();
|
73 |
+
}
|
74 |
+
|
75 |
+
return $contact;
|
76 |
+
}
|
77 |
+
}
|
app/code/community/Nicklasmoeller/Billysbilling/Model/Country.php
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Nicklasmoeller_Billysbilling_Model_Country
|
5 |
+
*
|
6 |
+
* @author Nicklas Møller <hello@nicklasmoeller.com>
|
7 |
+
* @version 0.2.0
|
8 |
+
*/
|
9 |
+
class Nicklasmoeller_Billysbilling_Model_Country extends Nicklasmoeller_Billysbilling_Model_Abstract
|
10 |
+
{
|
11 |
+
/**
|
12 |
+
* @var
|
13 |
+
*/
|
14 |
+
private $countries;
|
15 |
+
|
16 |
+
/**
|
17 |
+
* @var
|
18 |
+
*/
|
19 |
+
private $country;
|
20 |
+
|
21 |
+
/**
|
22 |
+
* @param $countryId
|
23 |
+
*
|
24 |
+
* @return bool|mixed
|
25 |
+
*/
|
26 |
+
public function getCountry($countryId)
|
27 |
+
{
|
28 |
+
if (!$this->countries) {
|
29 |
+
$res = $this->client->request("GET", "/countries");
|
30 |
+
|
31 |
+
if ($res->status !== 200) {
|
32 |
+
return false;
|
33 |
+
}
|
34 |
+
|
35 |
+
$this->countries = $res->body->countries;
|
36 |
+
}
|
37 |
+
|
38 |
+
foreach ($this->countries as $country) {
|
39 |
+
if ($country->id == $countryId) {
|
40 |
+
$this->country = $country->id;
|
41 |
+
break;
|
42 |
+
}
|
43 |
+
}
|
44 |
+
|
45 |
+
return $this->country;
|
46 |
+
}
|
47 |
+
|
48 |
+
}
|
app/code/community/Nicklasmoeller/Billysbilling/Model/Currency.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Nicklasmoeller_Billysbilling_Model_Currency
|
5 |
+
*
|
6 |
+
* @author Nicklas Møller <hello@nicklasmoeller.com>
|
7 |
+
* @version 0.2.0
|
8 |
+
*/
|
9 |
+
class Nicklasmoeller_Billysbilling_Model_Currency extends Nicklasmoeller_Billysbilling_Model_Abstract
|
10 |
+
{
|
11 |
+
public $currency;
|
12 |
+
|
13 |
+
/**
|
14 |
+
* @param $currencyId
|
15 |
+
*
|
16 |
+
* @return bool|mixed
|
17 |
+
*/
|
18 |
+
public function getCurrency($currencyId)
|
19 |
+
{
|
20 |
+
if ($this->currency) {
|
21 |
+
return $this->currency;
|
22 |
+
}
|
23 |
+
|
24 |
+
$res = $this->client->request("GET", "/currencies/" . $currencyId);
|
25 |
+
|
26 |
+
if ($res->status !== 200) {
|
27 |
+
return false;
|
28 |
+
}
|
29 |
+
|
30 |
+
$this->currency = $res->body->currency;
|
31 |
+
|
32 |
+
return $this->currency;
|
33 |
+
}
|
34 |
+
}
|
app/code/community/Nicklasmoeller/Billysbilling/Model/Invoice.php
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Nicklasmoeller_Billysbilling_Model_Invoice
|
5 |
+
*
|
6 |
+
* @author Nicklas Møller <hello@nicklasmoeller.com>
|
7 |
+
* @version 0.2.0
|
8 |
+
*/
|
9 |
+
class Nicklasmoeller_Billysbilling_Model_Invoice extends Nicklasmoeller_Billysbilling_Model_Abstract
|
10 |
+
{
|
11 |
+
/**
|
12 |
+
* @var
|
13 |
+
*/
|
14 |
+
protected $invoice;
|
15 |
+
|
16 |
+
/**
|
17 |
+
* @param $orderData
|
18 |
+
* @param $contact
|
19 |
+
* @param $observerType
|
20 |
+
*
|
21 |
+
* @return mixed
|
22 |
+
*/
|
23 |
+
public function getInvoice($orderData, $contact, $observerType)
|
24 |
+
{
|
25 |
+
$invoice = $this->buildInvoice($orderData, $contact, $observerType);
|
26 |
+
|
27 |
+
return $invoice;
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* @param $orderData
|
32 |
+
* @param $contact
|
33 |
+
* @param $observerType
|
34 |
+
*
|
35 |
+
* @return bool|mixed
|
36 |
+
*/
|
37 |
+
public function buildInvoice($orderData, $contact, $observerType)
|
38 |
+
{
|
39 |
+
if ($observerType == 'sales_order_creditmemo_refund') {
|
40 |
+
$type = 'creditNote';
|
41 |
+
$paymentTermsDays = null;
|
42 |
+
|
43 |
+
$invoicePrefix = "c";
|
44 |
+
} elseif ($observerType == 'sales_order_invoice_register') {
|
45 |
+
$type = 'invoice';
|
46 |
+
$paymentTermsDays = 8;
|
47 |
+
|
48 |
+
$invoicePrefix = "";
|
49 |
+
}
|
50 |
+
|
51 |
+
$entryDate = date('Y-m-d');
|
52 |
+
|
53 |
+
$invoice = new stdClass();
|
54 |
+
|
55 |
+
$invoice->organizationId = Mage::getSingleton('billysbilling/organization')->getOrganizationId();
|
56 |
+
$invoice->contactId = $contact->id;
|
57 |
+
$invoice->type = $type;
|
58 |
+
$invoice->state = 'approved';
|
59 |
+
$invoice->invoiceNo = $invoicePrefix . $orderData->getId();
|
60 |
+
$invoice->currencyId = Mage::getSingleton('billysbilling/currency')->getCurrency($orderData->getOrderCurrencyCode())->id;
|
61 |
+
$invoice->entryDate = $entryDate;
|
62 |
+
$invoice->paymentTermsDays = $paymentTermsDays;
|
63 |
+
$invoice->taxMode = 'excl';
|
64 |
+
|
65 |
+
$invoice->lines = $this->buildInvoiceLines($orderData);
|
66 |
+
|
67 |
+
$res = $this->client->request("POST", "/invoices", [
|
68 |
+
'invoice' => $invoice
|
69 |
+
]);
|
70 |
+
|
71 |
+
if ($res->status !== 200) {
|
72 |
+
return false;
|
73 |
+
}
|
74 |
+
|
75 |
+
$this->invoice = $res->body->invoices[0];
|
76 |
+
|
77 |
+
return $this->invoice;
|
78 |
+
}
|
79 |
+
|
80 |
+
/**
|
81 |
+
* @param $orderData
|
82 |
+
*
|
83 |
+
* @return array
|
84 |
+
*/
|
85 |
+
public function buildInvoiceLines($orderData)
|
86 |
+
{
|
87 |
+
$lines = [];
|
88 |
+
|
89 |
+
$products = $orderData->getAllItems();
|
90 |
+
|
91 |
+
$this->client->request("GET", "/invoices");
|
92 |
+
|
93 |
+
$i = 0;
|
94 |
+
|
95 |
+
foreach ($products as $product) {
|
96 |
+
$tempProduct = Mage::getSingleton('billysbilling/product')->getProduct($product);
|
97 |
+
|
98 |
+
Mage::log($tempProduct, null, 'product.log');
|
99 |
+
|
100 |
+
$lines[$i] = new stdClass();
|
101 |
+
$lines[$i]->productId = $tempProduct->id;
|
102 |
+
$lines[$i]->description = '';
|
103 |
+
$lines[$i]->quantity = $product->getQtyOrdered();
|
104 |
+
$lines[$i]->unitPrice = $product->getPrice();
|
105 |
+
|
106 |
+
if ($product->getDiscountAmount() > 0) {
|
107 |
+
$lines[$i]->discountText = 'Discounted';
|
108 |
+
$lines[$i]->discountMode = 'cash';
|
109 |
+
$lines[$i]->discountValue = $product->getDiscountAmount();
|
110 |
+
}
|
111 |
+
|
112 |
+
$i++;
|
113 |
+
}
|
114 |
+
|
115 |
+
$lines[$i] = Mage::getSingleton('billysbilling/shipment')->getShipping($orderData);
|
116 |
+
|
117 |
+
return $lines;
|
118 |
+
}
|
119 |
+
}
|
app/code/community/Nicklasmoeller/Billysbilling/Model/Observer.php
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Nicklasmoeller_Billysbilling_Model_Observer
|
5 |
+
*
|
6 |
+
* @author Nicklas Møller <hello@nicklasmoeller.com>
|
7 |
+
* @version 0.2.0
|
8 |
+
*/
|
9 |
+
class Nicklasmoeller_Billysbilling_Model_Observer extends Nicklasmoeller_Billysbilling_Model_Abstract
|
10 |
+
{
|
11 |
+
/**
|
12 |
+
* @var
|
13 |
+
*/
|
14 |
+
private $orderData;
|
15 |
+
/**
|
16 |
+
* @var
|
17 |
+
*/
|
18 |
+
private $billingAddress;
|
19 |
+
|
20 |
+
/**
|
21 |
+
* @var
|
22 |
+
*/
|
23 |
+
private $event;
|
24 |
+
|
25 |
+
/**
|
26 |
+
* @param Varien_Event_Observer $observer
|
27 |
+
*
|
28 |
+
* @return bool
|
29 |
+
*/
|
30 |
+
public function billysObserver(Varien_Event_Observer $observer)
|
31 |
+
{
|
32 |
+
if (!Mage::helper('billysbilling')->isApiKeySet() || !Mage::helper('billysbilling')->isEnabled()) {
|
33 |
+
return false;
|
34 |
+
}
|
35 |
+
|
36 |
+
$this->event = $observer->getEvent();
|
37 |
+
|
38 |
+
if ($this->event->getName() == 'sales_order_creditmemo_refund') {
|
39 |
+
$this->orderData = $observer->getCreditmemo()->getOrder();
|
40 |
+
} else {
|
41 |
+
$this->orderData = $observer->getOrder();
|
42 |
+
}
|
43 |
+
|
44 |
+
$this->billingAddress = $this->orderData->getBillingAddress();
|
45 |
+
|
46 |
+
$contact = Mage::getModel('billysbilling/contact')->getCustomer($this->billingAddress);
|
47 |
+
|
48 |
+
$invoice = Mage::getModel('billysbilling/invoice')->getInvoice($this->orderData, $contact, $this->event->getName());
|
49 |
+
}
|
50 |
+
}
|
app/code/community/Nicklasmoeller/Billysbilling/Model/Organization.php
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Nicklasmoeller_Billysbilling_Model_Organization
|
5 |
+
*
|
6 |
+
* @author Nicklas Møller <hello@nicklasmoeller.com>
|
7 |
+
* @version 0.2.0
|
8 |
+
*/
|
9 |
+
class Nicklasmoeller_Billysbilling_Model_Organization extends Nicklasmoeller_Billysbilling_Model_Abstract
|
10 |
+
{
|
11 |
+
protected $organizationId;
|
12 |
+
|
13 |
+
/**
|
14 |
+
* @return bool|int
|
15 |
+
*/
|
16 |
+
public function getOrganizationId()
|
17 |
+
{
|
18 |
+
if ($this->organizationId) {
|
19 |
+
return $this->organizationId;
|
20 |
+
}
|
21 |
+
|
22 |
+
$res = $this->client->request("GET", "/organization");
|
23 |
+
|
24 |
+
if ($res->status !== 200) {
|
25 |
+
return false;
|
26 |
+
}
|
27 |
+
|
28 |
+
$this->organizationId = $res->body->organization->id;
|
29 |
+
|
30 |
+
return $this->organizationId;
|
31 |
+
}
|
32 |
+
}
|
app/code/community/Nicklasmoeller/Billysbilling/Model/Product.php
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Nicklasmoeller_Billysbilling_Model_Product
|
5 |
+
*
|
6 |
+
* @author Nicklas Møller <hello@nicklasmoeller.com>
|
7 |
+
* @version 0.2.0
|
8 |
+
*/
|
9 |
+
class Nicklasmoeller_Billysbilling_Model_Product extends Nicklasmoeller_Billysbilling_Model_Abstract
|
10 |
+
{
|
11 |
+
/**
|
12 |
+
* @param $product
|
13 |
+
*
|
14 |
+
* @return bool|mixed
|
15 |
+
*/
|
16 |
+
public function getProduct($product)
|
17 |
+
{
|
18 |
+
$tempProduct = $this->buildProduct($product);
|
19 |
+
|
20 |
+
$res = $this->client->request("GET", "/products?productNo=" . $tempProduct->productNo);
|
21 |
+
|
22 |
+
if ($res->body->meta->paging->total > 0) {
|
23 |
+
return $res->body->products[0];
|
24 |
+
}
|
25 |
+
|
26 |
+
$res = $this->client->request("POST", "/products", array(
|
27 |
+
'product' => $tempProduct
|
28 |
+
));
|
29 |
+
|
30 |
+
if ($res->status !== 200) {
|
31 |
+
return false;
|
32 |
+
}
|
33 |
+
|
34 |
+
return $res->body->products[0];
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* @param $productData
|
39 |
+
*
|
40 |
+
* @return mixed
|
41 |
+
*/
|
42 |
+
public function buildProduct($productData)
|
43 |
+
{
|
44 |
+
$product = new stdClass();
|
45 |
+
|
46 |
+
$product->organizationId = Mage::getSingleton('billysbilling/organization')->getOrganizationId();
|
47 |
+
$product->name = $productData->getName();
|
48 |
+
$product->description = $productData->getDescription();
|
49 |
+
$product->productNo = $productData->getSku();
|
50 |
+
$product->prices = array(
|
51 |
+
$this->buildPrice($productData->getPrice())
|
52 |
+
);
|
53 |
+
|
54 |
+
return $product;
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* @param $productDataPrice
|
59 |
+
*
|
60 |
+
* @return mixed
|
61 |
+
*/
|
62 |
+
public function buildPrice($productDataPrice)
|
63 |
+
{
|
64 |
+
$price = new stdClass();
|
65 |
+
|
66 |
+
$price->unitPrice = $productDataPrice;
|
67 |
+
$price->currencyId = Mage::getSingleton('billysbilling/currency')->currency->id;
|
68 |
+
|
69 |
+
return $price;
|
70 |
+
}
|
71 |
+
}
|
app/code/community/Nicklasmoeller/Billysbilling/Model/Shipment.php
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Nicklasmoeller_Billysbilling_Model_Shipment
|
5 |
+
*
|
6 |
+
* @author Nicklas Møller <hello@nicklasmoeller.com>
|
7 |
+
* @version 0.2.0
|
8 |
+
*/
|
9 |
+
class Nicklasmoeller_Billysbilling_Model_Shipment extends Nicklasmoeller_Billysbilling_Model_Abstract
|
10 |
+
{
|
11 |
+
/**
|
12 |
+
* @param $orderData
|
13 |
+
*
|
14 |
+
* @return bool|mixed
|
15 |
+
*/
|
16 |
+
public function getShipping($orderData)
|
17 |
+
{
|
18 |
+
$shipping = $this->buildShipping($orderData);
|
19 |
+
|
20 |
+
$res = $this->client->request("GET", "/products?productNo=" . $shipping->productNo);
|
21 |
+
|
22 |
+
if ($res->body->meta->paging->total > 0) {
|
23 |
+
return $this->buildShippingLine($res->body->products[0], $orderData);
|
24 |
+
}
|
25 |
+
|
26 |
+
$res = $this->client->request("POST", "/products", array(
|
27 |
+
'product' => $shipping
|
28 |
+
));
|
29 |
+
|
30 |
+
if ($res->status !== 200) {
|
31 |
+
return false;
|
32 |
+
}
|
33 |
+
|
34 |
+
$product = $res->body->products[0];
|
35 |
+
|
36 |
+
return $this->buildShippingLine($product, $orderData);
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* @param $orderData
|
41 |
+
*
|
42 |
+
* @return mixed
|
43 |
+
*/
|
44 |
+
public function buildShipping($orderData)
|
45 |
+
{
|
46 |
+
$shipping = new stdClass();
|
47 |
+
|
48 |
+
$shipping->organizationId = Mage::getSingleton('billysbilling/organization')->getOrganizationId();
|
49 |
+
$shipping->name = 'Fragt';
|
50 |
+
$shipping->description = $orderData->getShippingDescription();
|
51 |
+
$shipping->productNo = $orderData->getShippingMethod();
|
52 |
+
$shipping->salesTaxRulesetId = $this->client->request('GET', '/salesTaxRulesets?abbreviation=F')->body->salesTaxRulesets[0]->id;
|
53 |
+
$shipping->prices = array(
|
54 |
+
Mage::getSingleton('billysbilling/product')->buildPrice($orderData->getShippingInvoiced())
|
55 |
+
);
|
56 |
+
|
57 |
+
return $shipping;
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* @param $shipping
|
62 |
+
* @param $orderData
|
63 |
+
*
|
64 |
+
* @return mixed
|
65 |
+
*/
|
66 |
+
public function buildShippingLine($shipping, $orderData)
|
67 |
+
{
|
68 |
+
$newLine = new stdClass();
|
69 |
+
$newLine->productId = $shipping->id;
|
70 |
+
$newLine->description = $shipping->description;
|
71 |
+
$newLine->quantity = 1;
|
72 |
+
$newLine->unitPrice = $orderData->getShippingInvoiced();
|
73 |
+
|
74 |
+
return $newLine;
|
75 |
+
}
|
76 |
+
}
|
app/code/community/Nicklasmoeller/Billysbilling/etc/adminhtml.xml
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" ?>
|
2 |
+
<config>
|
3 |
+
<acl>
|
4 |
+
<resources>
|
5 |
+
<all>
|
6 |
+
<title>Allow Everything</title>
|
7 |
+
</all>
|
8 |
+
<admin>
|
9 |
+
<children>
|
10 |
+
<system>
|
11 |
+
<children>
|
12 |
+
<config>
|
13 |
+
<children>
|
14 |
+
<billysbilling translate="title" module="billysbilling">
|
15 |
+
<title>Billy's Billing</title>
|
16 |
+
<sort_order>1</sort_order>
|
17 |
+
</billysbilling>
|
18 |
+
</children>
|
19 |
+
</config>
|
20 |
+
</children>
|
21 |
+
</system>
|
22 |
+
</children>
|
23 |
+
</admin>
|
24 |
+
</resources>
|
25 |
+
</acl>
|
26 |
+
</config>
|
app/code/community/Nicklasmoeller/Billysbilling/etc/config.xml
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Nicklasmoeller_Billysbilling>
|
5 |
+
<version>0.1.2</version>
|
6 |
+
</Nicklasmoeller_Billysbilling>
|
7 |
+
</modules>
|
8 |
+
|
9 |
+
<global>
|
10 |
+
<helpers>
|
11 |
+
<billysbilling>
|
12 |
+
<class>Nicklasmoeller_Billysbilling_Helper</class>
|
13 |
+
</billysbilling>
|
14 |
+
</helpers>
|
15 |
+
<models>
|
16 |
+
<billysbilling>
|
17 |
+
<class>Nicklasmoeller_Billysbilling_Model</class>
|
18 |
+
</billysbilling>
|
19 |
+
</models>
|
20 |
+
|
21 |
+
<events>
|
22 |
+
<sales_order_invoice_register>
|
23 |
+
<observers>
|
24 |
+
<billysbilling_invoice_register_success>
|
25 |
+
<type>singleton</type>
|
26 |
+
<class>billysbilling/observer</class>
|
27 |
+
<method>billysObserver</method>
|
28 |
+
</billysbilling_invoice_register_success>
|
29 |
+
</observers>
|
30 |
+
</sales_order_invoice_register>
|
31 |
+
|
32 |
+
<sales_order_creditmemo_refund>
|
33 |
+
<observers>
|
34 |
+
<billysbilling_creditmemo_register_success>
|
35 |
+
<type>singleton</type>
|
36 |
+
<class>billysbilling/observer</class>
|
37 |
+
<method>billysObserver</method>
|
38 |
+
</billysbilling_creditmemo_register_success>
|
39 |
+
</observers>
|
40 |
+
</sales_order_creditmemo_refund>
|
41 |
+
</events>
|
42 |
+
</global>
|
43 |
+
<default>
|
44 |
+
<billysbilling>
|
45 |
+
<settings>
|
46 |
+
<enabled>1</enabled>
|
47 |
+
</settings>
|
48 |
+
</billysbilling>
|
49 |
+
</default>
|
50 |
+
</config>
|
app/code/community/Nicklasmoeller/Billysbilling/etc/system.xml
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<sections>
|
4 |
+
<billysbilling translate="label" module="billysbilling">
|
5 |
+
<label>Billy's Billing</label>
|
6 |
+
<tab>service</tab>
|
7 |
+
<sort_order>400</sort_order>
|
8 |
+
<show_in_default>1</show_in_default>
|
9 |
+
<show_in_website>0</show_in_website>
|
10 |
+
<show_in_store>0</show_in_store>
|
11 |
+
<groups>
|
12 |
+
<settings translate="label">
|
13 |
+
<label>General Settings</label>
|
14 |
+
<frontend_type>text</frontend_type>
|
15 |
+
<sort_order></sort_order>
|
16 |
+
<show_in_default>1</show_in_default>
|
17 |
+
<show_in_website>0</show_in_website>
|
18 |
+
<show_in_store>0</show_in_store>
|
19 |
+
<fields>
|
20 |
+
<enabled translate="label">
|
21 |
+
<label>Enable</label>
|
22 |
+
<comment><![CDATA[Set this to no, if you want the extension to be inactive for some reason]]></comment>
|
23 |
+
<frontend_type>select</frontend_type>
|
24 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
25 |
+
<sort_order>10</sort_order>
|
26 |
+
<show_in_default>1</show_in_default>
|
27 |
+
<show_in_website>0</show_in_website>
|
28 |
+
<show_in_store>0</show_in_store>
|
29 |
+
</enabled>
|
30 |
+
</fields>
|
31 |
+
</settings>
|
32 |
+
<api translate="label">
|
33 |
+
<label>API Settings</label>
|
34 |
+
<frontend_type>text</frontend_type>
|
35 |
+
<sort_order>500</sort_order>
|
36 |
+
<show_in_default>1</show_in_default>
|
37 |
+
<show_in_website>0</show_in_website>
|
38 |
+
<show_in_store>0</show_in_store>
|
39 |
+
<fields>
|
40 |
+
<key translate="label">
|
41 |
+
<label>API key</label>
|
42 |
+
<comment><![CDATA[REQUIRED. Find this in the Billy's Billing application. It can be obtained in Settings > Access tokens]]></comment>
|
43 |
+
<frontend_type>text</frontend_type>
|
44 |
+
<sort_order>10</sort_order>
|
45 |
+
<show_in_default>1</show_in_default>
|
46 |
+
<show_in_website>0</show_in_website>
|
47 |
+
<show_in_store>0</show_in_store>
|
48 |
+
</key>
|
49 |
+
</fields>
|
50 |
+
</api>
|
51 |
+
</groups>
|
52 |
+
</billysbilling>
|
53 |
+
</sections>
|
54 |
+
</config>
|
app/etc/modules/Nicklasmoeller_Billysbilling.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Nicklasmoeller_Billysbilling>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
</Nicklasmoeller_Billysbilling>
|
8 |
+
</modules>
|
9 |
+
</config>
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Nicklasmoeller_BillysBilling</name>
|
4 |
-
<version>0.2.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
|
7 |
<channel>community</channel>
|
@@ -10,11 +10,11 @@
|
|
10 |
<description>Billy's Billing enables you to keep your focus on selling, rather than all the hassle with accounting. It automatically sends your data through Billy's Billing API v2.
|
11 |

|
12 |
It will trigger when you create credit memos and invoices, and submit the order data.</description>
|
13 |
-
<notes>
|
14 |
<authors><author><name>Nicklas Møller</name><user>nicklasmoeller</user><email>hello@nicklasmoeller.com</email></author></authors>
|
15 |
-
<date>2015-01-
|
16 |
-
<time>
|
17 |
-
<contents><target name="mageetc"><dir name="modules"><file name="
|
18 |
<compatible/>
|
19 |
<dependencies><required><php><min>5.2.0</min><max>5.6.4</max></php></required></dependencies>
|
20 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Nicklasmoeller_BillysBilling</name>
|
4 |
+
<version>0.2.1</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
|
7 |
<channel>community</channel>
|
10 |
<description>Billy's Billing enables you to keep your focus on selling, rather than all the hassle with accounting. It automatically sends your data through Billy's Billing API v2.
|
11 |

|
12 |
It will trigger when you create credit memos and invoices, and submit the order data.</description>
|
13 |
+
<notes>Fix renaming issues between alpha and first stable</notes>
|
14 |
<authors><author><name>Nicklas Møller</name><user>nicklasmoeller</user><email>hello@nicklasmoeller.com</email></author></authors>
|
15 |
+
<date>2015-01-06</date>
|
16 |
+
<time>13:10:58</time>
|
17 |
+
<contents><target name="mageetc"><dir name="modules"><file name="Nicklasmoeller_Billysbilling.xml" hash=""/></dir></target><target name="magecommunity"><dir name="Nicklasmoeller"><dir name="Billysbilling"><dir name="Helper"><file name="Data.php" hash="f4736eba20bc2d9c7fcedf64a7633204"/></dir><dir name="Model"><file name="Abstract.php" hash="5c6d911c3ffb7cb9b4a01ac110b6bb0b"/><file name="Client.php" hash="bfefb24176325e119735777e66055069"/><file name="Contact.php" hash="6cac465d3def83ecc5b7023ea1fce0f1"/><file name="Country.php" hash="00719daadf5e6b1bf33d20c871b88bbe"/><file name="Currency.php" hash="f0fc753816c8a701a3f4a2a77e538b19"/><file name="Invoice.php" hash="1f66a77cb8b4bea4b4ec4bc1a673c556"/><file name="Observer.php" hash="415a0dd2fa5a994f7cae110ae4d4a230"/><file name="Organization.php" hash="3c9878026777e83c37a0d6d5fbaa7bdd"/><file name="Product.php" hash="eb05e67dba21ee3aac0c929c583f9622"/><file name="Shipment.php" hash="f994dda14c629a2885de0af7a4b3a2e0"/></dir><dir name="etc"><file name="adminhtml.xml" hash="6a3fdd657b1c112c61bb2700564f34ad"/><file name="config.xml" hash="59d4ee6d454c3aa47eb24716e8c9c4f7"/><file name="system.xml" hash="9ff46b75b2ba25efa7fae13c9cbb376f"/></dir></dir></dir></target></contents>
|
18 |
<compatible/>
|
19 |
<dependencies><required><php><min>5.2.0</min><max>5.6.4</max></php></required></dependencies>
|
20 |
</package>
|