diff --git a/api/order.go b/api/order.go
index 59b82e67445105373d67e7a59a7c45cb874ef136..4a65572b8e8d679eeea4493d7ff768cde63edd14 100644
--- a/api/order.go
+++ b/api/order.go
@@ -36,6 +36,11 @@ type OrderPurchase struct {
 	Ammount       int      `json:"ammount"`
 }
 
+type OrderGetResponse struct {
+	Order       Order        `json:"order"`
+	Transaction *Transaction `json:"transaction"`
+}
+
 func (a *api) refundOrders() {
 	const refundSleeptime = 10 * time.Minute
 	for {
@@ -133,23 +138,21 @@ func (a *api) GetOrder(num int, w http.ResponseWriter, req *http.Request) {
 		w.WriteHeader(http.StatusInternalServerError)
 		return
 	}
-	var body struct {
-		Order       Order        `json:"order"`
-		Transaction *Transaction `json:"transaction"`
-	}
+	var body OrderGetResponse
 	body.Order = order
 
 	var transaction Transaction
-	err = a.db.Joins("OrderPurchase").
-		Where("member = ? AND type = 'order' AND order_purchases.order_id = ?", num, order.ID).
+	err = a.db.Where("member = ? AND type = 'order' AND id IN (?)", num,
+		a.db.Table("order_purchases").
+			Where("order_id = ?", order.ID).
+			Select("transaction_id")).
 		Find(&transaction).Error
 	if err != nil {
-		if err.Error() != "record not found" {
-			log.Printf("Can't get order transaction %s: %v", vars["id"], err)
-			w.WriteHeader(http.StatusInternalServerError)
-			return
-		}
-	} else {
+		log.Printf("Can't get order transaction %s: %v", vars["id"], err)
+		w.WriteHeader(http.StatusInternalServerError)
+		return
+	}
+	if transaction.ID != 0 {
 		body.Transaction = &transaction
 	}
 
diff --git a/api/order_test.go b/api/order_test.go
index da66d1420d6745f15b8c91c62e50e0392353300e..b11144a7266f72a8f8a14ad7ca7ac085d4920bc4 100644
--- a/api/order_test.go
+++ b/api/order_test.go
@@ -3,6 +3,7 @@ package api
 import (
 	"net/http"
 	"path"
+	"strconv"
 	"testing"
 	"time"
 )
@@ -224,6 +225,58 @@ func TestOrderDeactivation(t *testing.T) {
 	}
 }
 
+func TestGetOrder(t *testing.T) {
+	tapi := newTestAPI(t)
+	defer tapi.close()
+	tapi.addTestMember()
+	tapi.addTestOrder()
+
+	var orders []Order
+	resp := tapi.do("GET", "/order/active", nil, &orders)
+	if resp.StatusCode != http.StatusOK {
+		t.Fatal("Can't get orders:", resp.Status)
+	}
+	if len(orders) != 1 {
+		t.Fatal("Didn't find my new order")
+	}
+	id := strconv.Itoa(int(orders[0].ID))
+
+	var body OrderGetResponse
+	resp = tapi.do("GET", "/order/"+id, nil, &body)
+	if resp.StatusCode != http.StatusOK {
+		t.Fatal("Can't get order:", resp.Status)
+	}
+	if body.Transaction != nil {
+		t.Error("Unexpected transaction", body.Transaction)
+	}
+	if body.Order.Name != testOrder.Name {
+		t.Error("Wrong name:", body.Order.Name)
+	}
+
+	purchase := []OrderPurchase{
+		{
+			ProductCode: testProduct.Code,
+			Ammount:     3,
+			OrderID:     orders[0].ID,
+		},
+	}
+	resp = tapi.do("POST", "/order/purchase", purchase, nil)
+	if resp.StatusCode != http.StatusCreated {
+		t.Fatal("Can't create order:", resp.Status)
+	}
+
+	resp = tapi.do("GET", "/order/"+id, nil, &body)
+	if resp.StatusCode != http.StatusOK {
+		t.Fatal("Can't get order:", resp.Status)
+	}
+	if body.Transaction == nil {
+		t.Fatal("There is no transaction")
+	}
+	if body.Transaction.Type != "order" {
+		t.Error("Wrong transaction type", body.Transaction.Type)
+	}
+}
+
 func (tapi *testAPI) addTestOrder() {
 	resp := tapi.do("POST", "/order", testOrder, nil)
 	if resp.StatusCode != http.StatusCreated {