-
Notifications
You must be signed in to change notification settings - Fork 822
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves brave/brave-browser#11284
- Loading branch information
Showing
16 changed files
with
729 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/payment/payment_server.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "bat/ledger/internal/endpoint/payment/payment_server.h" | ||
|
||
#include "bat/ledger/internal/ledger_impl.h" | ||
|
||
namespace ledger { | ||
namespace endpoint { | ||
|
||
PaymentServer::PaymentServer(bat_ledger::LedgerImpl* ledger): | ||
ledger_(ledger), | ||
post_order_(new payment::PostOrder(ledger)) { | ||
DCHECK(ledger_); | ||
} | ||
|
||
PaymentServer::~PaymentServer() = default; | ||
|
||
payment::PostOrder* PaymentServer::post_order() const { | ||
return post_order_.get(); | ||
} | ||
|
||
} // namespace endpoint | ||
} // namespace ledger |
36 changes: 36 additions & 0 deletions
36
vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/payment/payment_server.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVELEDGER_ENDPOINT_PAYMENT_PAYMENT_SERVER_H_ | ||
#define BRAVELEDGER_ENDPOINT_PAYMENT_PAYMENT_SERVER_H_ | ||
|
||
#include <memory> | ||
|
||
#include "bat/ledger/ledger.h" | ||
#include "bat/ledger/internal/endpoint/payment/post_order/post_order.h" | ||
|
||
namespace bat_ledger { | ||
class LedgerImpl; | ||
} | ||
|
||
namespace ledger { | ||
namespace endpoint { | ||
|
||
class PaymentServer { | ||
public: | ||
explicit PaymentServer(bat_ledger::LedgerImpl* ledger); | ||
~PaymentServer(); | ||
|
||
payment::PostOrder* post_order() const; | ||
|
||
private: | ||
bat_ledger::LedgerImpl* ledger_; // NOT OWNED | ||
std::unique_ptr<payment::PostOrder> post_order_; | ||
}; | ||
|
||
} // namespace endpoint | ||
} // namespace ledger | ||
|
||
#endif // BRAVELEDGER_ENDPOINT_PAYMENT_PAYMENT_SERVER_H_ |
39 changes: 39 additions & 0 deletions
39
vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/payment/payment_util.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "bat/ledger/internal/endpoint/payment/payment_util.h" | ||
|
||
#include "bat/ledger/ledger.h" | ||
|
||
namespace ledger { | ||
namespace endpoint { | ||
namespace payment { | ||
|
||
const char kDevelopment[] = "https://payment.rewards.brave.software"; | ||
const char kStaging[] = "http://payment.rewards.bravesoftware.com"; | ||
const char kProduction[] = "http://payment.rewards.brave.com"; | ||
|
||
std::string GetServerUrl(const std::string& path) { | ||
DCHECK(!path.empty()); | ||
|
||
std::string url; | ||
switch (ledger::_environment) { | ||
case ledger::Environment::DEVELOPMENT: | ||
url = kDevelopment; | ||
break; | ||
case ledger::Environment::STAGING: | ||
url = kStaging; | ||
break; | ||
case ledger::Environment::PRODUCTION: | ||
url = kProduction; | ||
break; | ||
} | ||
|
||
return url + path; | ||
} | ||
|
||
} // namespace payment | ||
} // namespace endpoint | ||
} // namespace ledger |
21 changes: 21 additions & 0 deletions
21
vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/payment/payment_util.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVELEDGER_ENDPOINT_PAYMENT_PAYMENT_UTIL_H_ | ||
#define BRAVELEDGER_ENDPOINT_PAYMENT_PAYMENT_UTIL_H_ | ||
|
||
#include <string> | ||
|
||
namespace ledger { | ||
namespace endpoint { | ||
namespace payment { | ||
|
||
std::string GetServerUrl(const std::string& path); | ||
|
||
} // namespace payment | ||
} // namespace endpoint | ||
} // namespace ledger | ||
|
||
#endif // BRAVELEDGER_ENDPOINT_PAYMENT_PAYMENT_UTIL_H_ |
41 changes: 41 additions & 0 deletions
41
vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/payment/payment_util_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "bat/ledger/global_constants.h" | ||
#include "bat/ledger/internal/endpoint/payment/payment_util.h" | ||
#include "bat/ledger/ledger.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
// npm run test -- brave_unit_tests --filter=PaymentUtilTest.* | ||
|
||
namespace ledger { | ||
namespace endpoint { | ||
namespace payment { | ||
|
||
class PaymentUtilTest : public testing::Test { | ||
}; | ||
|
||
TEST(PaymentUtilTest, GetServerUrlDevelopment) { | ||
ledger::_environment = ledger::Environment::DEVELOPMENT; | ||
const std::string url = GetServerUrl("/test"); | ||
const std::string expected_url = ""; | ||
ASSERT_EQ(url, "https://payment.rewards.brave.software/test"); | ||
} | ||
|
||
TEST(PaymentUtilTest, GetServerUrlStaging) { | ||
ledger::_environment = ledger::Environment::STAGING; | ||
const std::string url = GetServerUrl("/test"); | ||
ASSERT_EQ(url, "https://payment.rewards.bravesoftware.com/test"); | ||
} | ||
|
||
TEST(PaymentUtilTest, GetServerUrlProduction) { | ||
ledger::_environment = ledger::Environment::PRODUCTION; | ||
const std::string url = GetServerUrl("/test"); | ||
ASSERT_EQ(url, "https://payment.rewards.brave.com/test"); | ||
} | ||
|
||
} // namespace payment | ||
} // namespace endpoint | ||
} // namespace ledger |
Oops, something went wrong.