android - 在 Android 中集成 Dibs 支付网关

标签 android payment-gateway payment payment-processing dibs

我正在处理 Dibs 支付集成,但无法取得成功。所有东西在演示模式下都运行良好,但是当向它提供商家 ID 时,然后在打开卡详细信息表单之前它会给出错误“数据已被篡改。校验无效”。我不知道那是什么。在我谷歌搜索之后,我发现它与计算的 MAC 有关,但如何在我的代码中计算 MAC。我的整个类(class)付款如下,所有评论。

public class CheckOut extends Activity {

private static final String TAG = "DIBS." + CheckOut.class.getSimpleName();

private DibsPayment paymentWindow;
public static String total, resname, resid, userid, menunames, itemnames,
        itemquantity, ordertype, address, city, contactno, pincode,
        deliverttime, orderid;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.checkout);
    RandomStringGenerator randomorderid = new RandomStringGenerator();
    Intent i = getIntent();
    // total=String.valueOf(1);
    total = i.getStringExtra("grandTotal");
    resname = i.getStringExtra("res_name");
    resid = i.getStringExtra("res_id");
    userid = i.getStringExtra("user_id");
    menunames = i.getStringExtra("menu_names");
    itemnames = i.getStringExtra("item_prices");
    itemquantity = i.getStringExtra("item_quantity");
    ordertype = i.getStringExtra("ordertype");
    address = i.getStringExtra("address");
    city = i.getStringExtra("city");
    contactno = i.getStringExtra("phone");
    pincode = i.getStringExtra("pin");
    deliverttime = i.getStringExtra("delivery_time");
    orderid = randomorderid.getAlphaNumeric(5);
    Toast.makeText(
            getApplicationContext(),
            orderid + "\n" + resname + "\n" + resid + "\n" + userid + "\n"
                    + ordertype + "\n" + address + "\n" + city + "\n"
                    + pincode + "\n" + contactno + "\n" + deliverttime
                    + "\n" + menunames + "\n" + itemnames + "\n"
                    + itemquantity + "\n" + total, Toast.LENGTH_SHORT)
            .show();
    /*
     * Intent intent=getIntent(); String []
     * arrayList=intent.getStringArrayExtra("payment_item"); // int l_itr =
     * arrayList.length; // while(l_itr.hasNext()) { for(int
     * i=0;i<=arrayList.length-1;i++){
     * 
     * @SuppressWarnings("rawtypes") //HashMap l_map = (HashMap)
     * l_itr.next(); String item=arrayList[i]; Log.v(item, "item"); String
     * item =(String)i.get(DatabaseHandler.KEY_ITEM); Log.v(item, "item");
     * String unicost= (String)l_map.get(DatabaseHandler.KEY_UNITCOST);
     * Log.v(unicost, "unicost"); String l_res_name = (String)
     * l_map.get(DatabaseHandler.KEY_QUANTITY); Log.v(l_res_name,
     * "quantity"); String l_street = (String)
     * l_map.get(DatabaseHandler.KEY_TOTAL); Log.v(l_street, "total"); }
     */

    paymentWindow = (DibsPayment) findViewById(R.id.DibsPayment);

    // Set your listener implementation, to get callbacks in the life-cycle
    // of a payment processing
    paymentWindow
            .setPaymentResultListener(new MyPaymentResultListener(this));

    // Load the payment window with the payment data that suits the payment
    // flow you need
    // Please be patient, when loading on the emulator
    paymentWindow.loadPaymentWindow(constructPaymentData());
}

/**
 * Shows a "cancel" action in the options menu on the phone, which shows how
 * to call cancel functionality into the payment window to cancel ongoing
 * payment processing.
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.payment_window_menu, menu);
    return true;
}

/**
 * If user chose "cancel" in options menu, we call "cancel" into payment
 * window.
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menuitem_payment_window_cancel:
        //
        // Calling cancel into payment window cancels the ongoing payment
        // processing.
        // Because cancelling is an asynchronous process, you will need to
        // wait for a callback
        // to paymentCancelled on your PaymentResultListener listener,
        // before being positive that
        // payment window is done cancelling.
        //
        paymentWindow.cancelPayment();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

/**
 * @return the payment data instance that is needed as input to
 *         {@link DibsPayment#loadPaymentWindow(dk.dibs.android.library.PaymentData)}
 */
private PaymentData constructPaymentData() {
    // IMPORTANT: This needs to be set to YOUR merchant number, that you
    // have obtained through an
    // agreement with DIBS.
    // you can use the merchant "demo" for a demorun through the payment
    // window // read information about demo mode in the documentation

     String merchantId = "******";
    //String merchantId = "demo";

    // The currency the payment is to be processed in
    String currencyCode = "DKK";

    // You set this to your own orderId value
    String yourOrderId = orderid;

    // The amount to be paid, given in "least possible unit" (aka: "oerer")
    long amount = (new Double(total)).longValue();
    // The cards that is allowed to be used in payment window
    List<String> payTypes = new ArrayList<String>();
    payTypes.add("MC");
    payTypes.add("MTRO");
    payTypes.add("VISA");

    // this will add fee to the payment window.
    boolean calcfee = true;

    // In this example, we simply use "PurchasePaymentData", which is a
    // simple "buy-with-credit-card" flow,
    // where no pre-authorization is performed.
    //
    // Look to other subclasses of PaymentData for the other supported
    // flows.
    //
    PurchasePaymentData paymentData = new PurchasePaymentData(merchantId,
            currencyCode, yourOrderId, amount, payTypes);

    paymentData.setCalcfee(calcfee);

    // Set this flag to "true", if you want to be able to use test cards.
    // REMEMBER to reset this to false, in production !!!
    paymentData.setTest(true);

    // If you want checks (and payment failure) if the orderId you gave
    // already have been payed.
    paymentData.setUseUniqueOrderIdCheck(false);

    // If you want MAC security calculations, you will need to pre-calculate
    // a MAC value on your server,
    // based on the values you give to this payment window, and set this
    // pre-calculated MAC value like this.
    //
     paymentData.setCalculatedMAC("");

    // Payment window supports loading cancel or callback URLs based on
    // payment outcome.
    // Another, and maybe better, way to do this in an app, is to listen for
    // the proper callbacks
    // on the listener you set on the payment window, and then do your own
    // cancel or payment success
    // handling against your own servers.
    //

    try {
        paymentData.setCallbackUrl(new URL(
                "http://****.demoprojects.in/accept.php"));
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        paymentData.setCancelUrl(new URL("http://****.demoprojects.in/accept.php"));
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    paymentData.setLanguage("en_UK");
    paymentData.setTheme(Theme.ANDROID_DIBS);

    // If you need to, you can pass custom options to the payment window,
    // which will be posted back again.
    //
    // Map<String, String> yourCustomOptions = new HashMap<String,
    // String>();
    // yourCustomOptions.put("foo", "bar");
    // paymentData.setCustomOptions(yourCustomOptions);

    return paymentData;
}

/*
 * public void delete() { DatabaseHandler readDatabase = new
 * DatabaseHandler( getApplicationContext()); readDatabase.deleteAll(); }
 */
}

这是我第一次处理付款。请帮助我,因为安全是这里的主要问题。 提前致谢:)

最佳答案

Dibs 允许通过两种算法计算 MAC 算法的选择由您决定。它目前处理 MD5 和 SHA-1。 Dibs 推荐 SHA-1,因为它提供更好的安全性。

SHA-1(data&currency&method&SecretKey&)

MD5(data&currency&method&SecretKey&)

此处的数据是包含有关购买金额和数量信息的字符串。

Security > DebiTech DefenderTM > MAC Configuration,在这里您可以找到 dibs 仪表板中的 key 。

点击here进一步引用:

关于android - 在 Android 中集成 Dibs 支付网关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16231330/

相关文章:

drupal-7 - drupal 7的ubercart 3.x中成功付款的钩子(Hook)是什么

java - "AnalyticsReceiver is not registered or is disabled."

android - 如何以编程方式重命名 SD 卡中的音频文件?

paypal - 如何防止欺诈?

payment-gateway - 沙盒中的 Authorize.net 信用卡收费在响应中返回 refTransID 为空

android - Google Play Android Developer API 更改同一次购买的初始购买时间

javascript - 在使用 Stripe 支付的处理订单期间禁用提交输入,或者如果 Stripe 弹出窗口消失则启用它们

java - 向另一台设备发送通知

android - 使用 HTTP POST 发送大于 1MB 的文件

ios - UIWebView 没有打开安全的 url