Example usage for java.util Currency getInstance

List of usage examples for java.util Currency getInstance

Introduction

In this page you can find the example usage for java.util Currency getInstance.

Prototype

public static Currency getInstance(Locale locale) 

Source Link

Document

Returns the Currency instance for the country of the given locale.

Usage

From source file:com.github.woki.payments.adyen.ClientPaymentsTest.java

@Before
public void setUp() {
    client = Client.endpoint("http://localhost:" + port).credentials("test_user", "test_password").build();
    req = PaymentRequestBuilder.merchantAccount("test_merchant_account")
            .amount(new Amount(Currency.getInstance("USD"), 10)).build();
}

From source file:fr.pasteque.client.models.Payment.java

public Currency getCurrency() {
    return Currency.getInstance("EUR");
}

From source file:org.sparkcommerce.openadmin.server.service.persistence.module.provider.MoneyFieldPersistenceProvider.java

@Override
protected Currency getCurrency(ExtractValueRequest extractValueRequest, Property property) {
    String currencyCodeField = extractValueRequest.getMetadata().getCurrencyCodeField();
    if (!StringUtils.isEmpty(currencyCodeField)) {
        try {//from ww  w.  ja  v  a2s.  c  o  m
            return Currency.getInstance((String) extractValueRequest.getFieldManager()
                    .getFieldValue(extractValueRequest.getEntity(), currencyCodeField));
        } catch (Exception e) {
            //do nothing
        }
    }
    if (extractValueRequest.getEntity() instanceof CurrencyCodeIdentifiable) {
        try {
            return Currency.getInstance(
                    ((CurrencyCodeIdentifiable) extractValueRequest.getEntity()).getCurrencyCode());
        } catch (Exception e) {
            //do nothing
        }
    }
    SparkRequestContext brc = SparkRequestContext.getSparkRequestContext();
    return brc.getJavaCurrency();
}

From source file:org.broadleafcommerce.openadmin.server.service.persistence.module.provider.MoneyFieldPersistenceProvider.java

@Override
protected Currency getCurrency(ExtractValueRequest extractValueRequest, Property property) {
    String currencyCodeField = extractValueRequest.getMetadata().getCurrencyCodeField();
    if (!StringUtils.isEmpty(currencyCodeField)) {
        try {/*from   w ww. ja va 2s.c o  m*/
            return Currency.getInstance((String) extractValueRequest.getFieldManager()
                    .getFieldValue(extractValueRequest.getEntity(), currencyCodeField));
        } catch (Exception e) {
            //do nothing
        }
    }
    if (extractValueRequest.getEntity() instanceof CurrencyCodeIdentifiable) {
        try {
            return Currency.getInstance(
                    ((CurrencyCodeIdentifiable) extractValueRequest.getEntity()).getCurrencyCode());
        } catch (Exception e) {
            //do nothing
        }
    }
    BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
    return brc.getJavaCurrency();
}

From source file:org.broadleafcommerce.vendor.CyberSourcePaymentServiceTest.java

@Test(groups = { "testSuccessfulCyberSourceCCPayment" })
@Rollback(false)/* www.  ja  va2s.  c om*/
public void testSuccessfulCyberSourceCCPayment() throws Exception {
    if (serviceManager.getMerchantId().equals("?")) {
        return;
    }

    System.out.println("***Initiating testSuccessfulCyberSourceCCPayment***");

    /*
     * authorize the amount
     */
    CyberSourceCardRequest cardRequest = new CyberSourceCardRequest();
    cardRequest.setTransactionType(CyberSourceTransactionType.AUTHORIZE);
    cardRequest.setCurrency(Currency.getInstance(Locale.US).getCurrencyCode());

    CyberSourceBillingRequest billingRequest = new CyberSourceBillingRequest();
    billingRequest.setCity("Mountain View");
    billingRequest.setFirstName("John");
    billingRequest.setLastName("Doe");
    billingRequest.setPostalCode("94043");
    billingRequest.setIpAddress("10.7.111.111");
    billingRequest.setState("CA");
    billingRequest.setStreet1("1295 Charleston Road");
    billingRequest.setCountry("US");
    billingRequest.setEmail("null@cybersource.com");

    cardRequest.setBillingRequest(billingRequest);

    CyberSourceItemRequest itemRequest1 = new CyberSourceItemRequest();
    itemRequest1.setDescription("First Item");
    itemRequest1.setQuantity(2L);
    itemRequest1.setShortDescription("firstItem");
    itemRequest1.setUnitPrice(new Money(12.34));

    cardRequest.getItemRequests().add(itemRequest1);

    CyberSourceItemRequest itemRequest2 = new CyberSourceItemRequest();
    itemRequest2.setDescription("Second Item");
    itemRequest2.setQuantity(1L);
    itemRequest2.setShortDescription("secondItem");
    itemRequest2.setUnitPrice(new Money(56.78));

    cardRequest.getItemRequests().add(itemRequest2);

    cardRequest.setAccountNumber("4111111111111111");
    cardRequest.setExpirationMonth(12);
    cardRequest.setExpirationYear(2020);

    CyberSourcePaymentService service = (CyberSourcePaymentService) serviceManager.getValidService(cardRequest);
    CyberSourceCardResponse response = (CyberSourceCardResponse) service.process(cardRequest);

    assert (response.getAuthResponse().getAmount().doubleValue() > 0D);
    assert (response.getReasonCode().intValue() == 100);

    /*cardRequest.setAccountNumber("12345");
    CyberSourceCardResponse rejectResponse = (CyberSourceCardResponse) service.process(cardRequest);
    assert(rejectResponse.isErrorDetected());
            
    cardRequest.setAccountNumber("4111111111111111");
    cardRequest.getBillingRequest().setLastName(null);
    PaymentException hostException = null;
    try {
    service.process(cardRequest);
    } catch (PaymentException e) {
    hostException = e;
    }
    assert(hostException != null && hostException instanceof PaymentHostException);
    cardRequest.getBillingRequest().setLastName("Doe");*/

    /*
     * capture
     */
    CyberSourceCardRequest cardRequest2 = new CyberSourceCardRequest();
    cardRequest2.setTransactionType(CyberSourceTransactionType.CAPTURE);
    cardRequest2.setCurrency(Currency.getInstance(Locale.US).getCurrencyCode());
    cardRequest2.setRequestID(response.getRequestID());
    cardRequest2.setRequestToken(response.getRequestToken());
    cardRequest2.getItemRequests().add(itemRequest1);
    cardRequest2.getItemRequests().add(itemRequest2);

    CyberSourceCardResponse response2 = (CyberSourceCardResponse) service.process(cardRequest2);

    assert (response2.getReasonCode().intValue() == 100);

    /*
     * authorize and capture
     */
    cardRequest.setTransactionType(CyberSourceTransactionType.AUTHORIZEANDCAPTURE);
    CyberSourceCardResponse response3 = (CyberSourceCardResponse) service.process(cardRequest);

    assert (response3.getAuthResponse().getAmount().doubleValue() > 0D);
    assert (response3.getCaptureResponse().getAmount().doubleValue() > 0D);
    assert (response3.getReasonCode().intValue() == 100);

    /*
     * credit
     */
    CyberSourceCardRequest cardRequest4 = new CyberSourceCardRequest();
    cardRequest4.setTransactionType(CyberSourceTransactionType.CREDIT);
    cardRequest4.setCurrency(Currency.getInstance(Locale.US).getCurrencyCode());
    cardRequest4.setRequestID(response3.getRequestID());
    cardRequest4.setRequestToken(response3.getRequestToken());
    cardRequest4.getItemRequests().add(itemRequest1);
    cardRequest4.getItemRequests().add(itemRequest2);

    CyberSourceCardResponse response4 = (CyberSourceCardResponse) service.process(cardRequest4);

    assert (response4.getReasonCode().intValue() == 100);

    /*
     * void
     */
    //TODO does not appear to be working in the CyberSource test environment
    /*
    cardRequest.setTransactionType(CyberSourceTransactionType.AUTHORIZEANDCAPTURE);
    CyberSourceCardResponse response5 = (CyberSourceCardResponse) service.process(cardRequest);
            
    CyberSourceCardRequest cardRequest6 = new CyberSourceCardRequest();
    cardRequest6.setTransactionType(CyberSourceTransactionType.VOIDTRANSACTION);
    cardRequest6.setServiceType(CyberSourceServiceType.PAYMENT);
    cardRequest6.setMethodType(CyberSourceMethodType.CREDITCARD);
    cardRequest6.setCurrency(Currency.getInstance(Locale.US).getCurrencyCode());
    cardRequest6.setRequestID(response5.getRequestID());
    cardRequest6.setRequestToken(response5.getRequestToken());
            
    CyberSourceCardResponse response6 = (CyberSourceCardResponse) service.process(cardRequest6);
            
    assert(response6.getReasonCode().intValue() == 100);
    */

    /*
     * reverse authorize
     */
    cardRequest.setTransactionType(CyberSourceTransactionType.AUTHORIZE);
    CyberSourceCardResponse response7 = (CyberSourceCardResponse) service.process(cardRequest);

    CyberSourceCardRequest cardRequest7 = new CyberSourceCardRequest();
    cardRequest7.setTransactionType(CyberSourceTransactionType.REVERSEAUTHORIZE);
    cardRequest7.setCurrency(Currency.getInstance(Locale.US).getCurrencyCode());
    cardRequest7.setRequestID(response7.getRequestID());
    cardRequest7.setRequestToken(response7.getRequestToken());
    cardRequest7.getItemRequests().add(itemRequest1);
    cardRequest7.getItemRequests().add(itemRequest2);

    CyberSourceCardResponse response8 = (CyberSourceCardResponse) service.process(cardRequest7);

    assert (response8.getReasonCode().intValue() == 100);
}

From source file:com.playhaven.android.req.PurchaseTrackingRequest.java

@Override
protected UriComponentsBuilder createUrl(Context context) throws PlayHavenException {
    UriComponentsBuilder builder = super.createUrl(context);

    if (purchase != null) {
        PlayHaven.d("Using: %s", purchase);
        SharedPreferences pref = PlayHaven.getPreferences(context);

        addNonNull(builder, "product", purchase.getSKU());
        addNonNull(builder, "quantity", purchase.getQuantity());
        addNonNull(builder, "placement_tag", purchase.getPlacementTag());
        Purchase.Result result = purchase.getResult();
        if (result != null)
            addNonNull(builder, "resolution", result.getUrlValue());

        String store = purchase.getStore();
        if (store == null) {
            // This tells us where we were installed from -- not where the purchase happened!
            store = context.getPackageManager()
                    .getInstallerPackageName(getString(pref, PlayHaven.Config.AppPkg));
        }//from  w ww .j ava 2  s  .  c  o  m
        addNonNull(builder, "store", store == null ? "sideload" : store);
        addNonNull(builder, "cookie", purchase.getCookie());
        addNonNull(builder, "price", purchase.getPrice());
        addNonNull(builder, "price_locale", Currency.getInstance(Locale.getDefault()).getCurrencyCode());
        addNonNull(builder, "payload", purchase.getPayload());
        addNonNull(builder, "order_id", purchase.getOrderId());
    }

    return builder;
}

From source file:ivl.android.moneybalance.CalculationEditorActivity.java

private static Currency getDefaultCurrency() {
    Locale locale = Locale.getDefault();
    return Currency.getInstance(locale);
}

From source file:org.mayocat.shop.cart.internal.DefaultCartLoaderTest.java

private void runTest(String name) throws Exception {
    cartContents = new CartContents(Currency.getInstance("EUR"));

    CartTestDefinition definition = loadTest(name);

    // Mock settings
    TaxesService taxesService = componentManager.getInstance(TaxesService.class);
    ConfigurationService configurationService = componentManager.getInstance(ConfigurationService.class);
    TaxesSettings settings = definition.getTaxesSettings();
    if (settings == null) {
        settings = new TaxesSettings();
    }/*  w  w  w .  ja  v  a  2 s  . c o  m*/
    when(configurationService.getSettings(TaxesSettings.class)).thenReturn(settings);

    // Mock web context
    WebContext webContext = componentManager.getInstance(WebContext.class);
    when(webContext.getTenant()).thenReturn(null);

    // Mock tenant store
    TenantStore tenantStore = componentManager.getInstance(TenantStore.class);
    when(tenantStore.findById(any(UUID.class))).thenReturn(new Tenant());

    CartTest test = definition.getTest();
    TestInput input = test.getInput();
    TestExpectation expectation = test.getExpected();

    for (InputItem item : input.getItems()) {
        Product p = new Product();
        p.setId(UUID.randomUUID());
        p.setPrice(item.getUnitPrice());

        cartContents.addItem(p, item.getQuantity());
    }

    CartLoader cartLoader = componentManager.getInstance(CartLoader.class);

    Cart cart = cartLoader.load(cartContents);

    assertEquivalent(expectation.getItemsTotal(), cart.itemsTotal());

    Assert.assertEquals(expectation.getItems().size(), cart.items().size());

    Integer i = 0;
    for (ItemExpectation itemExpectation : expectation.getItems()) {
        assertEquivalent(itemExpectation.getUnitPrice(), cart.items().get(i).unitPrice());
        assertEquivalent(itemExpectation.getTotal(), cart.items().get(i).total());
        i++;
    }
}

From source file:org.yestech.lib.currency.Money.java

public Money(String amount, Locale locale) {
    BigDecimal tmpAmount;//  w ww  .j a  va  2s.  c  o  m
    if (StringUtils.isBlank(amount) || !NumberUtils.isNumber(amount)) {
        throw new CurrencyException("money amount must be a positive number");
    } else {
        tmpAmount = new BigDecimal(amount);
        validateAmount(tmpAmount);
    }
    if (locale == null) {
        throw new CurrencyException("can't have a null locale");
    }
    this.amount = tmpAmount;
    this.locale = locale;
    this.curreny = Currency.getInstance(locale);
}

From source file:com.github.woki.payments.adyen.ClientPaymentsTest.java

@Test(expected = APSAccessException.class)
public void testClientCSEError() {
    Client cli = Client.endpoint(APUtil.TEST_ENDPOINT).credentials("merchant", "password")
            .encryptionKey(PUBKEY_TEXT_ERR1).build();
    cli.authorise(PaymentRequestBuilder.merchantAccount("mrchntacct")
            .amount(new Amount(Currency.getInstance("EUR"), 1000L))
            .card(CardBuilder.number("4111111111111111").cvc("737").expiry(2016, 6).holder("Johnny Tester Visa")
                    .build())/*w  w w  .j  a  v a  2s  .  c o  m*/
            .reference(reference(ReferenceType.UUID))
            .shopper(NameBuilder.first("Willian").last("Oki").build(), "willian.oki@gmail.com", "127.0.0.1",
                    "Test/DAPI/Authorisation/Willian Oki", ShopperInteraction.Ecommerce)
            .build());
}