Showing posts with label refund. Show all posts
Showing posts with label refund. Show all posts

Wednesday, December 28, 2011

in-app billing關於使用者退款後,Google的心態。

很好奇萬一使用者退款了,
那我們程式這邊要不要把使用介面還原成未付費的樣子。

底下是in-app billing範例程式中,
PurchaseDatabase.java裡的其中一個函式updatePurchase(),
這個函式在您的APP收到使用者退款通知時,
會做資料庫購買記錄的修改。

底下是原始碼︰
 

   /**
     * Adds the given purchase information to the database and returns the total
     * number of times that the given product has been purchased.
     * @param orderId a string identifying the order
     * @param productId the product ID (sku)
     * @param purchaseState the purchase state of the product
     * @param purchaseTime the time the product was purchased, in milliseconds
     * since the epoch (Jan 1, 1970)
     * @param developerPayload the developer provided "payload" associated with
     *            the order
     * @return the number of times the given product has been purchased.
     */
    public synchronized int updatePurchase(String orderId, String productId,

        PurchaseState purchaseState, long purchaseTime, String developerPayload) {

        insertOrder(orderId, productId, purchaseState, purchaseTime, developerPayload);

        Cursor cursor = mDb.query(PURCHASE_HISTORY_TABLE_NAME, HISTORY_COLUMNS,
                HISTORY_PRODUCT_ID_COL + "=?", new String[] { productId }, null, null, null, null);

        if (cursor == null) {
            return 0;
        }

        int quantity = 0;

        try {

           // Count the number of times the product was purchased
            while (cursor.moveToNext()) {

                int stateIndex = cursor.getInt(2);
                PurchaseState state = PurchaseState.valueOf(stateIndex);

                // Note that a refunded purchase is treated as a purchase. Such
                // a friendly refund policy is nice for the user.
                if (state == PurchaseState.PURCHASED || state == PurchaseState.REFUNDED) {
                    quantity += 1;
                }

            }

            // Update the "purchased items" table
            updatePurchasedItem(productId, quantity);

        } finally {

            if (cursor != null) {
                cursor.close();
            }

        }

        return quantity;

    }
 

以上這段code説的、也做的夠清楚了,
範例程式收到使用者退款的IN_APP_NOTIFY後,
直接把Purchase Database的購買數量減1
卻沒有對程式畫面做任何處理。

範例裡留了這一段註解︰
// Note that a refunded purchase is treated as a purchase. Such a friendly refund policy is nice for the user.
即使使用者退款了,
我們仍以使用者是已購買的狀態來對待他,
這是一種友善政策。