Example #1
0
 public void onClick(View v) {
   MyApplication myApp = ((MyApplication) getApplication());
   String name = acctName.getText().toString();
   PaymentMethod newMethod = new PaymentMethod();
   newMethod.setName(name);
   newMethod.setInfo("");
   myApp.addAccount(newMethod);
   Toast.makeText(
           getApplicationContext(),
           myApp.paymentNames().get(myApp.accountsSize() - 1) + "has been added",
           Toast.LENGTH_LONG)
       .show();
 }
Example #2
0
  public void validateCardNumber(Context context, PaymentMethod paymentMethod) throws Exception {

    // Empty field
    if (TextUtils.isEmpty(cardNumber)) {
      throw new Exception(context.getString(R.string.mpsdk_invalid_empty_card));
    }

    Setting setting =
        Setting.getSettingByBin(
            paymentMethod.getSettings(),
            (cardNumber.length() >= MercadoPago.BIN_LENGTH
                ? cardNumber.substring(0, MercadoPago.BIN_LENGTH)
                : ""));

    if (setting == null) {

      // Invalid bin
      throw new Exception(context.getString(R.string.mpsdk_invalid_card_bin));

    } else {

      // Validate card length
      int cardLength = setting.getCardNumber().getLength();
      if (cardNumber.trim().length() != cardLength) {
        throw new Exception(context.getString(R.string.mpsdk_invalid_card_length, cardLength));
      }

      // Validate luhn
      String luhnAlgorithm = setting.getCardNumber().getValidation();
      if (("standard".equals(luhnAlgorithm)) && (!checkLuhn(cardNumber))) {
        throw new Exception(context.getString(R.string.mpsdk_invalid_card_luhn));
      }
    }
  }
  @Override
  public int hashCode() {
    HashCodeBuilder builder = new HashCodeBuilder();

    boolean present_chosenItems = true && (isSetChosenItems());
    builder.append(present_chosenItems);
    if (present_chosenItems) builder.append(chosenItems);

    boolean present_expectedPrice = true;
    builder.append(present_expectedPrice);
    if (present_expectedPrice) builder.append(expectedPrice);

    boolean present_userId = true;
    builder.append(present_userId);
    if (present_userId) builder.append(userId);

    boolean present_howWillPay = true && (isSetHowWillPay());
    builder.append(present_howWillPay);
    if (present_howWillPay) builder.append(howWillPay.getValue());

    boolean present_pickUp = true;
    builder.append(present_pickUp);
    if (present_pickUp) builder.append(pickUp);

    boolean present_address = true && (isSetAddress());
    builder.append(present_address);
    if (present_address) builder.append(address);

    boolean present_phoneNumber = true && (isSetPhoneNumber());
    builder.append(present_phoneNumber);
    if (present_phoneNumber) builder.append(phoneNumber);

    boolean present_timestamp = true;
    builder.append(present_timestamp);
    if (present_timestamp) builder.append(timestamp);

    boolean present_tableId = true && (isSetTableId());
    builder.append(present_tableId);
    if (present_tableId) builder.append(tableId);

    boolean present_phoneId = true && (isSetPhoneId());
    builder.append(present_phoneId);
    if (present_phoneId) builder.append(phoneId);

    boolean present_orderId = true;
    builder.append(present_orderId);
    if (present_orderId) builder.append(orderId);

    boolean present_username = true && (isSetUsername());
    builder.append(present_username);
    if (present_username) builder.append(username);

    return builder.toHashCode();
  }
Example #4
0
  public static void validateSecurityCode(
      Context context, String securityCode, PaymentMethod paymentMethod, String bin)
      throws Exception {

    if (paymentMethod != null) {
      Setting setting = Setting.getSettingByBin(paymentMethod.getSettings(), bin);

      // Validate security code length
      if (setting != null) {
        int cvvLength = setting.getSecurityCode().getLength();
        if ((cvvLength != 0) && (securityCode.trim().length() != cvvLength)) {
          throw new Exception(context.getString(R.string.mpsdk_invalid_cvv_length, cvvLength));
        }
      } else {
        throw new Exception(context.getString(R.string.mpsdk_invalid_field));
      }
    }
  }
 public static PaymentAccount getPaymentAccount(PaymentMethod paymentMethod) {
   switch (paymentMethod.getId()) {
     case PaymentMethod.OK_PAY_ID:
       return new OKPayAccount();
     case PaymentMethod.PERFECT_MONEY_ID:
       return new PerfectMoneyAccount();
     case PaymentMethod.SEPA_ID:
       return new SepaAccount();
     case PaymentMethod.NATIONAL_BANK_ID:
       return new NationalBankAccount();
     case PaymentMethod.SAME_BANK_ID:
       return new SameBankAccount();
     case PaymentMethod.SPECIFIC_BANKS_ID:
       return new SpecificBanksAccount();
     case PaymentMethod.ALI_PAY_ID:
       return new AliPayAccount();
     case PaymentMethod.SWISH_ID:
       return new SwishAccount();
     case PaymentMethod.BLOCK_CHAINS_ID:
       return new CryptoCurrencyAccount();
     default:
       throw new RuntimeException("Not supported PaymentMethod: " + paymentMethod);
   }
 }
  /** Test for fetching zobjects when there is an object that matches the query */
  @Test
  public void getInvoice() throws Exception {

    // Setup Product details
    String productId = getTestProduct();
    String productRatePlanId = getTestProductRatePlan(productId);
    String productRateplanChargeId = getTestProductRatePlanCharge(productRatePlanId);

    assertNotNull(productId);
    assertNotNull(productRatePlanId);
    assertNotNull(productRateplanChargeId);

    SubscribeRequest subscribeReq = new SubscribeRequest();

    // subscribeReq.setAccount(testAccount());
    String uniqueString = UUID.randomUUID().toString();

    Contact contact = new Contact();
    contact.setFirstName(uniqueString);
    contact.setLastName(uniqueString);

    Account account = new Account();
    account.setName(uniqueString);
    account.setBillCycleDay(1);
    account.setCurrency("USD");
    account.setAllowInvoiceEdit(false);
    account.setAutoPay(false);
    account.setStatus("Draft");
    account.setPaymentTerm("Due Upon Receipt");
    account.setBatch("Batch1");

    PaymentMethod paymentMethod = new PaymentMethod();
    paymentMethod.setType("CreditCard");
    paymentMethod.setCreditCardNumber("5105105105105100");
    paymentMethod.setCreditCardType("Visa");
    paymentMethod.setCreditCardExpirationYear(2026);
    paymentMethod.setCreditCardExpirationMonth(5);
    paymentMethod.setCreditCardHolderName("Unit Test");

    // Generate Start and stop days for subscription
    XMLGregorianCalendar effectiveStartDate = null;
    XMLGregorianCalendar effectiveEndDate = null;
    try {
      GregorianCalendar calStart = new GregorianCalendar();
      // calStart.setTime(now);
      calStart.add(Calendar.DATE, -1);

      GregorianCalendar calEnd = new GregorianCalendar();
      // calEnd.setTime(now);
      calEnd.add(Calendar.DATE, 1);

      effectiveStartDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(calStart);
      effectiveEndDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(calStart);

    } catch (DatatypeConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    Subscription subscription = new Subscription();
    subscription.setContractAcceptanceDate(effectiveStartDate);
    subscription.setContractEffectiveDate(effectiveStartDate);
    subscription.setInitialTerm(12);
    subscription.setRenewalTerm(12);

    RatePlan ratePlan = new RatePlan();
    ratePlan.setProductRatePlanId(productRatePlanId);
    RatePlanData ratePlanData = new RatePlanData();
    ratePlanData.setRatePlan(ratePlan);

    SubscriptionData subscriptionData = new SubscriptionData();
    subscriptionData.setSubscription(subscription);
    subscriptionData.getRatePlanData().add(ratePlanData);

    subscribeReq.setAccount(account);
    subscribeReq.setBillToContact(contact);
    subscribeReq.setSoldToContact(contact);
    subscribeReq.setPaymentMethod(paymentMethod);
    subscribeReq.setSubscriptionData(subscriptionData);

    SubscribeResult subscribeResult =
        module.subscribe(Collections.singletonList(subscribeReq)).get(0);
    assertTrue(subscribeResult.isSuccess());
    assertEquals(0, subscribeResult.getErrors().size());

    Map<String, Object> result = module.getInvoice(subscribeResult.getInvoiceId());

    System.out.println("Result = " + result);

    assertEquals("Posted", result.get("status"));
    // assertEquals("amount",result.get("amount"));
    assertNotSame(0, ((ArrayList) result.get("invoiceitems")).size());

    assertNotNull(result.get("billTo"));
    assertNotNull(result.get("soldTo"));

    DeleteResult deleteResultAccount = null;
    DeleteResult deleteResultProduct = null;
    try {
      deleteResultAccount =
          module
              .delete(
                  ZObjectType.Account, Collections.singletonList(subscribeResult.getAccountId()))
              .get(0);
      deleteResultProduct =
          module.delete(ZObjectType.Product, Collections.singletonList(productId)).get(0);
    } catch (Exception e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
    assertTrue(deleteResultAccount.isSuccess());
    assertTrue(deleteResultProduct.isSuccess());
  }
  public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
    org.apache.thrift.protocol.TField field;
    iprot.readStructBegin();
    while (true) {
      field = iprot.readFieldBegin();
      if (field.type == org.apache.thrift.protocol.TType.STOP) {
        break;
      }
      switch (field.id) {
        case 1: // CHOSEN_ITEMS
          if (field.type == org.apache.thrift.protocol.TType.LIST) {
            {
              org.apache.thrift.protocol.TList _list24 = iprot.readListBegin();
              this.chosenItems = new ArrayList<ChosenMenuItem>(_list24.size);
              for (int _i25 = 0; _i25 < _list24.size; ++_i25) {
                ChosenMenuItem _elem26; // required
                _elem26 = new ChosenMenuItem();
                _elem26.read(iprot);
                this.chosenItems.add(_elem26);
              }
              iprot.readListEnd();
            }
          } else {
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 2: // EXPECTED_PRICE
          if (field.type == org.apache.thrift.protocol.TType.DOUBLE) {
            this.expectedPrice = iprot.readDouble();
            setExpectedPriceIsSet(true);
          } else {
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 3: // USER_ID
          if (field.type == org.apache.thrift.protocol.TType.I64) {
            this.userId = iprot.readI64();
            setUserIdIsSet(true);
          } else {
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 4: // HOW_WILL_PAY
          if (field.type == org.apache.thrift.protocol.TType.I32) {
            this.howWillPay = PaymentMethod.findByValue(iprot.readI32());
          } else {
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 5: // PICK_UP
          if (field.type == org.apache.thrift.protocol.TType.BOOL) {
            this.pickUp = iprot.readBool();
            setPickUpIsSet(true);
          } else {
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 6: // ADDRESS
          if (field.type == org.apache.thrift.protocol.TType.STRING) {
            this.address = iprot.readString();
          } else {
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 7: // PHONE_NUMBER
          if (field.type == org.apache.thrift.protocol.TType.STRING) {
            this.phoneNumber = iprot.readString();
          } else {
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 8: // TIMESTAMP
          if (field.type == org.apache.thrift.protocol.TType.I64) {
            this.timestamp = iprot.readI64();
            setTimestampIsSet(true);
          } else {
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 9: // TABLE_ID
          if (field.type == org.apache.thrift.protocol.TType.I64) {
            this.tableId = iprot.readI64();
            setTableIdIsSet(true);
          } else {
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 10: // PHONE_ID
          if (field.type == org.apache.thrift.protocol.TType.STRING) {
            this.phoneId = iprot.readString();
          } else {
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 11: // ORDER_ID
          if (field.type == org.apache.thrift.protocol.TType.I64) {
            this.orderId = iprot.readI64();
            setOrderIdIsSet(true);
          } else {
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 12: // USERNAME
          if (field.type == org.apache.thrift.protocol.TType.STRING) {
            this.username = iprot.readString();
          } else {
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        default:
          org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
      }
      iprot.readFieldEnd();
    }
    iprot.readStructEnd();

    // check for required fields of primitive type, which can't be checked in the validate method
    if (!isSetExpectedPrice()) {
      throw new org.apache.thrift.protocol.TProtocolException(
          "Required field 'expectedPrice' was not found in serialized data! Struct: " + toString());
    }
    if (!isSetUserId()) {
      throw new org.apache.thrift.protocol.TProtocolException(
          "Required field 'userId' was not found in serialized data! Struct: " + toString());
    }
    if (!isSetPickUp()) {
      throw new org.apache.thrift.protocol.TProtocolException(
          "Required field 'pickUp' was not found in serialized data! Struct: " + toString());
    }
    if (!isSetTimestamp()) {
      throw new org.apache.thrift.protocol.TProtocolException(
          "Required field 'timestamp' was not found in serialized data! Struct: " + toString());
    }
    if (!isSetOrderId()) {
      throw new org.apache.thrift.protocol.TProtocolException(
          "Required field 'orderId' was not found in serialized data! Struct: " + toString());
    }
    validate();
  }