How do I display the UI of the braintree in codename one? I only have this code `
Purchase.startOrder(new Purchase.Callback() {
public String fetchToken() {
}
public void onPurchaseSuccess(String nonce) {
}
public void onPurchaseFail(String errorMessage) {
}
public void onPurchaseCancel() {
}
});`
pls, I need a guide here. thanks
The call to startOrder will show the UI implicitly on the device once you implement the server side functionality that returns the token.
To test this in a mockup go to the braintree getting started guide you will notice code that looks like this:
public void onBraintreeSubmit(View v) {
DropInRequest dropInRequest = new DropInRequest()
.clientToken("long-token-string-that-looks-like-gibberish");
startActivityForResult(dropInRequest.getIntent(this), REQUEST_CODE);
}
You can use that token for debugging some of the process. Notice that price etc. are all determined in the server to prevent tampering so the token includes all of that data. I'd place the debug token here but I'm not sure if this is something that expires/changes.
Related
I'm going to do some unit tests and I am struggling with a MessageBox. I have a MessageBox that is showing a text and an "Ok" button in my code. When I trying to unit test the method that contains the MessageBox.Show("Text"), it pops up in the unit test, too, and I have to click "Ok" before it can pass through, which is a bad.
Does anyone know how to go around it? I think I need some kind of code that fakes this MessageBox and clicking "Ok", but I dont know how to do this. I'm a junior programmer, so please explain it as easy as you can ;) and gladly with some code examples.
This is my code for the MessageBox:
public void GetPopUpWithErrorMessage()
{
MessageBox.Show("Error Message", "text",
MessageBoxButton.OK);
}
Edit
I just realised that Fluent Assertions is used in the project. Does anyone know how to implement that in the test code? is it the same way as #thatguy showed?
You have to create a service that implements an interface that you can mock in your tests.
public interface IMessageBoxService
{
void ShowMessageBox(string title, string message);
}
public class MessageBoxService : IMessageBoxService
{
public void ShowMessageBox(string title, string message)
{
MessageBox.Show(message, title, MessageBoxButton.OK);
}
}
In the class where you use it, you would pass this service by its interface, e.g. in the constructor, so the class only knows its contract, but not its implementation.
public class MyClass
{
private IMessageBoxService _messageBoxService;
public MyClass(IMessageBoxService messageBoxService)
{
_messageBoxService = messageBoxService;
}
public void GetPopUpWithErrorMessage()
{
_messageBoxService.ShowMessageBox("text", "Error Message");
}
}
In the test class, you need to use a mocking framework like Moq that creates a mock object from an interface, which is just a stub that you can use to inject the behavior for any method or property that you use in your test.
In this example using NUnit and Moq, messageBoxService is created as a mock object that implements the IMessageBoxService interface. All methods do nothing unless you specify what they should do or return via Setup, but that is another topic. The last line shows how you could check if a sepcific method on the mock was invoked during the test.
[TestFixture]
public class MyClassTest
{
[Test]
public void MyTest()
{
var messageBoxService = Mock.Of<IMessageBoxService>();
var myClass = new MyClass(messageBoxService);
// ...your test code.
// Checks if the "ShowMessageBox" method in the service was called with any strings
Mock.Get(messageBoxService).Verify(mock => mock.ShowMessageBox(It.IsAny<string>(), It.IsAny<string>()));
}
}
Creating a service and an interface is not just useful for mocking, but also for separating view and logic, as you can extract the calling of a message box to a service which has an implementation hidden behind an interface. Moreover you can easily implement dependency injection via constructors.
Pls is the code below is enough to handle braintree for payment?
Purchase.startOrder(new Purchase.Callback() {
public String fetchToken() {
return "";
}
public void onPurchaseSuccess(String nonce) {
}
public void onPurchaseFail(String errorMessage) {
}
public void onPurchaseCancel() {
}
});
For the sample test I return the token provided in braintree websites like this
Purchase.startOrder(new Purchase.Callback() {
public String fetchToken() {
return "eyJ2ZXJzaW9uIjoyLCJhdXRob3JpemF0aW9uRmluZ2VycHJpbnQiOiI0ZDFkOWFkOGFhZDFlZDhiZjA4MDMwZGRmNWM0ZWEwZjc0ZDYwY2I4Zjg5MDNkYzVmYTUyNTM1MzhkMWIwYjNkfGNyZWF0ZWRfYXQ9MjAxNy0wNS0yMVQwNzo0MjoxNS4xODgzNDQ0MjIrMDAwMFx1MDAyNm1lcmNoYW50X2lkPTM0OHBrOWNnZjNiZ3l3MmJcdTAwMjZwdWJsaWNfa2V5PTJuMjQ3ZHY4OWJxOXZtcHIiLCJjb25maWdVcmwiOiJodHRwczovL2FwaS5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tOjQ0My9tZXJjaGFudHMvMzQ4cGs5Y2dmM2JneXcyYi9jbGllbnRfYXBpL3YxL2NvbmZpZ3VyYXRpb24iLCJjaGFsbGVuZ2VzIjpbXSwiZ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bnRJZCI6ImFjbWV3aWRnZXRzbHRkc2FuZGJveCIsImN1cnJlbmN5SXNvQ29kZSI6IlVTRCJ9LCJjb2luYmFzZUVuYWJsZWQiOmZhbHNlLCJtZXJjaGFudElkIjoiMzQ4cGs5Y2dmM2JneXcyYiIsInZlbm1vIjoib2ZmIn0=";
}
public void onPurchaseSuccess(String nonce) {
}
public void onPurchaseFail(String errorMessage) {
}
public void onPurchaseCancel() {
}
});
When I buit and install on my phone to test it out. It displays the payment method which include paypal and add debit or credit card.
When I want to integrate my own:
The problem am facing now is that at the server side, I have a code that provides client token
My questions:
1. How do I call this token in codename one, although I have code that says return "";. What am I going to return here? I pointed the url that generated the token inside the return. It didn't work.
2. If I get my own token is that enough to handle the payment? according to the code provided above.
3. Is ssl required on the server side I want to use?
Thanks for your response.
As explained in the post you need to have a server to implement payments. Instructions of implementing the server are in the braintree website which is linked too.
Just look in the server section there and implement that. You then need to return the token generated in the server to your client code.
I have been trying to call an oAuth evernote library without success. The authentication works but my Codename One app is not notified via the startActivityForResult() mechanism. I have trimmed out as many factors as I can. I have currently reduced it to startActivityForResult() using the Contact application.
I now have a Codename One native class with the following code. (This is an example from https://developer.android.com/guide/components/intents-common.html).
private void selectContact() {
debugOut ("selectContact: Entry");
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
AndroidNativeUtil.startActivityForResult(intent, new IntentResultListener() {
public void onActivityResult (int requestCode, int resultCode, Intent data) {
debugOut ("onActivityResult: Entry");
}
});
debugOut ("selectContact: Exit");
}
A call to selectContact() launches the Contact application. When I pick a Contact, the Contact application closes. The system console shows both messages: "selectContact: Entry" and "selectContact: Exit".
The code in IntentResultListener.onActivityResult() is not called (ie ""onActivityResult: Entry" is not output).
I have tried to look at the Codename One source on GitHub (CodenameOneActivity.java), in particular this:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//is this a payment result
if (mHelper != null && mHelper.handleActivityResult(requestCode, resultCode, data)) {
return;
}
IntentResult response = new IntentResult(requestCode, resultCode, data);
intentResult.add(response);
}
I'm likely looking in the wrong place but this does not appear to forward received Intents if it is not interested. (I am making an assumption that the cloud build uses CodenameOneActivity to build the Android app).
I think this effectively broke that functionality. I've filed an issue to track this.
I'm not able to figure out how to run a whole scenario before an other scenario, so that my test are not dependant on eachother.
I have this imaginary scenarios.
Scenario A
Given I have something
When I sumbit some data
I should see it on my webpage
Scenario B
Given SCENARIO A
When I delete the data
I should not see it on my webpage
When I run this scenario case, the software does not recognize Scenario A in scenario B, and ask me to create the step, like this...
You can implement missing steps with the snippets below:
#Given("^Registrere formue og inntekt$")
public void registrere_formue_og_inntekt() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
You could either:
Use a Background to group all the steps that need to be executed before the different scenarii:
Background:
Given I have something
When I submit some data
Then I should see it on my webpage
Scenario: B
When I delete the data
Then I should not see it on my webpage
Group them as part of a step definition:
#Given("^Scenario A")
public void scenario_A() {
I_have_something();
I_submit_some_data();
I_should_see_it_on_my_page();
}
which you can then use like this:
Given Scenario A
When I delete the data
Then I should not see it on my webpage
Using this technique, you usually observe that some actions are constantly reused, and you may want to factor them out so that they can be reused across different step definitions; at that point, the Page Object pattern comes very handy.
Cucumber scenarios are supposed to be independent. A lot of work is done assuming and ensuring that independence. Trying to go against will be an obstacle course.
Having said that, you could create your custom implementation of the Cucumber JUnit runner. Having this custom implementation, and by looking at the source of the original runner, you can expose / wrap / change the internals to allow what you want. For example with the following runner:
public class MyCucumber extends Cucumber {
private static Runtime runtime;
private static JUnitReporter reporter;
private static List<CucumberFeature> features;
public MyCucumber(Class<?> clazz) throws InitializationError, IOException {
super(clazz);
}
#Override
#SuppressWarnings("static-access")
protected Runtime createRuntime(ResourceLoader resourceLoader,
ClassLoader classLoader, RuntimeOptions runtimeOptions)
throws InitializationError, IOException {
this.runtime = super.createRuntime(resourceLoader, classLoader, runtimeOptions);
this.reporter = new JUnitReporter(runtimeOptions.reporter(classLoader), runtimeOptions.formatter(classLoader), runtimeOptions.isStrict());
this.features = runtimeOptions.cucumberFeatures(resourceLoader);
return this.runtime;
}
public static void runScenario(String name) throws Exception {
new ExecutionUnitRunner(runtime, getScenario(name), reporter).run(new RunNotifier());
}
private static CucumberScenario getScenario(String name) {
for (CucumberFeature feature : features) {
for (CucumberTagStatement element : feature.getFeatureElements()) {
if (! (element instanceof CucumberScenario)) {
continue;
}
CucumberScenario scenario = (CucumberScenario) element;
if (! name.equals(scenario.getGherkinModel().getName())) {
continue;
}
return scenario;
}
}
return null;
}
}
You can setup your test suite with:
#RunWith(MyCucumber.class)
public class MyTest {
}
And create a step definition like:
#Given("^I first run scenario (.*)$")
public void i_first_run_scenario(String name) throws Throwable {
MyCucumber.runScenario(name);
}
It is a fragile customization (can break easily with new versions of cucumber-junit) but it should work.
I've tried to setup the following configuration with SQL Server and SignalR
http://www.asp.net/signalr/overview/performance/scaleout-with-sql-server
Everything seems to be setup correctly, if I profile SQL server I can see SignalR making calls to the DB, but when I call the hub to send a message to all the clients connected, the message is never sent to the connected browsers.
any idea what could be the problem?
Thank you #smnbss, you just saved my life with your comment inside your question. Just to make it clear for everyone in the future with the same problem, here is the wrong implementation: I was getting the context only once like:
public class SyncService : ISyncService
{
private IHubContext StatusChangeHub { get; set; }
public GatewaySyncService()
{
StatusChangeHub = GlobalHost.ConnectionManager.GetHubContext<Hub>();
}
public void SyncStatusChange(Status newStatus)
{
StatusChangeHub.Clients.All.onStatusChange(newStatus);
}
}
But somehow this only work while not using a backplane. And the correct implementation: you need to get the context everytime you want to send a message:
public class SyncService : ISyncService
{
public void SyncStatusChange(Status newStatus)
{
var context = GlobalHost.ConnectionManager.GetHubContext<Hub>();
context.Clients.All.onStatusChange(newStatus);
}
}