Requesting Payment

In the second part of the purchase process, after the user has chosen to purchase a particular product, your app submits a payment request to the App Store, as shown in Figure 3-1.

购买过程的第二步是,在用户已经选择好要购买的产品后,你的应用程序向应用商店提交一个支付请求,如下图:

Figure 3-1  Stages of the purchase process—requesting payment

Creating a Payment Request

一、创建一个支付请求

When the user selects a product to buy, create a payment request using a product object, and set the quantity if needed, as shown in Listing 3-1. The product object comes from the array of products returned by your app’s products request, as discussed in “Retrieving Product Information.”

当用户选择了一个要买的产品后,使用一个产品对象创建一个支付请求,并根据需要设置好购买数量,如下列表。 正如In-App Purchase----(三) ----Retrieving Product Information 中所述,产品对象来自应用的products requst 返回的数组。

Listing 3-1  Creating a payment request

SKProduct *product = <# Product returned by a products request #>;
SKMutablePayment *payment = [SKMutablePayment paymentWithProduct:product];
payment.quantity = 2;

Detecting Irregular Activity

二、检测不规则活动

The App Store uses an irregular activity detection engine to help combat fraud. Some apps can provide additional information to improve the engine’s ability to detect unusual transactions. If your users have an account with you, in addition to their App Store accounts, provide this additional piece of information when requesting payment.

应用商店使用一个不规则活动检测引擎来帮助打击欺骗行为。 一个应用程序可以提供额外的信息来提高引擎的性能以便检测不正常的交易。 如果你的用户除了有自己的应用商店账号外,还有一个你的账号,就可以在请求支付时提供该额外的信息片段。

By way of illustration, consider the following two examples. In the normal case, many different users on your server each buy coins to use in your game, and each user pays for the purchase from a different App Store account. In contrast, it would be very unusual for a single user on your server to buy coins multiple times, paying for each purchase from a different App Store account. The App Store can’t detect this kind of irregular activity on its own—it needs information from your app about which account on your server is associated with the transaction.

通过演示的方法,考虑以下两个例子。 在正常情况下,你的服务器上的很多不同的用户购买游戏中金币(coins),并且每个用户都从一个不同的应用商店账号购买。相反,如果同一个用户在你的服务器上多次购买金币,但是每次购买都从不同的应用商店账号上支付就非常不寻常。应用商店自己不能检测到该类型的不规则活动--它需要从你的应用程序中知道你服务器上的哪个账号跟该笔交易有关联。

To provide this information, populate the applicationUsername property of the payment object with a one-way hash of the user’s account name on your server, such as in the example shown in Listing 3-2.

要想提供该信息,用你服务器中的用户账号名称,以单向散列方式填写applicationUsername特性,如下:

Listing 3-2  Providing an application username

#import <CommonCrypto/CommonCrypto.h>
 
// Custom method to calculate the SHA-256 hash using Common Crypto
- (NSString *)hashedValueForAccountName:(NSString*)userAccountName
{
    const int HASH_SIZE = 32;
    unsigned char hashedChars[HASH_SIZE];
    const char *accountName = [userAccountName UTF8String];
    size_t accountNameLen = strlen(accountName);
 
    // Confirm that the length of the user name is small enough
    // to be recast when calling the hash function.
    if (accountNameLen > UINT32_MAX) {
        NSLog(@"Account name too long to hash: %@", userAccountName);
        return nil;
    }
    CC_SHA256(accountName, (CC_LONG)accountNameLen, hashedChars);
 
    // Convert the array of bytes into a string showing its hex representation.
    NSMutableString *userAccountHash = [[NSMutableString alloc] init];
    for (int i = 0; i < HASH_SIZE; i++) {
        // Add a dash every four bytes, for readability.
        if (i != 0 && i%4 == 0) {
            [userAccountHash appendString:@"-"];
        }
        [userAccountHash appendFormat:@"%02x", hashedChars[i]];
    }
 
    return userAccountHash;
}

If you use another approach to populate this property, ensure that the value you provide is an opaque identifier uniquely associated with the user’s account on your server. Don’t use the Apple ID for your developer account, the user’s Apple ID, or the user’s unhashed account name on your server.

如果你使用另一种方法填写该特性,请确保你提供的值是一个不透明的识别码,它只跟你服务器上的用户账号有关。 不要使用苹果ID作为你的开发者账号,用户的苹果ID,或用户在你的服务器的非散列账户名。

Submitting a Payment Request

三、递交一个支付请求

Adding a payment request to the transaction queue submits it the App Store. If you add a payment object to the queue multiple times, it’s submitted multiple times—the user is charged multiple times and your app is expected to deliver the product multiple times.

向要递交给应用商店的交易队列添加一个支付请求。 如果你多次把一个支付对象添加到队列,它就会被提交多次---用户就会被多次要求支付并且应用程序就回多次传递产品。

[[SKPaymentQueue defaultQueue] addPayment:payment];

For every payment request your app submits, it gets back a corresponding transaction that it must process. Transactions and the transaction queue are discussed in “Waiting for the App Store to Process Transactions.”

对于你的应用程序递交的每个支付请求,都会返回一个相应地交易,它必须处理它。 交易和交易队列在“Waiting for the App Store to Process Transactions.”中讨论。

In-App Purchase Programming Guide----(四) ----Requesting Payment的更多相关文章

  1. In-App Purchase Programming Guide----(七) ----Restoring Purchased Products

    Restoring Purchased Products Users restore transactions to maintain access to content they’ve alread ...

  2. In-App Purchase Configuration Guide for iTunes Connect---(一)----Introduction

    Introduction In-App Purchase is an Apple technology that allows your users to purchase content and s ...

  3. In-App Purchase Programming Guide----(二) ---- Designing Your App’s Products

    Designing Your App’s Products A product is something you want to sell in your app’s store. You creat ...

  4. In-App Purchase Programming Guide----(八) ---- Preparing for App Review

    Preparing for App Review After you finish testing, you’re ready to submit your app for review. This ...

  5. View Programming Guide for iOS ---- iOS 视图编程指南(四)---Views

    Views Because view objects are the main way your application interacts with the user, they have many ...

  6. In-App Purchase Programming Guide----(一) ---- About In-App Purchase

    About In-App Purchase In-App Purchase allows you to embed a store inside your app using the Store Ki ...

  7. In-App Purchase Programming Guide----(三) ----Retrieving Product Information

    Retrieving Product Information In the first part of the purchase process, your app retrieves informa ...

  8. In-App Purchase Programming Guide----(六) ----Working with Subscriptions

    Working with Subscriptions Apps that use subscriptions have some additional behaviors and considerat ...

  9. In-App Purchase Programming Guide----(五) ----Delivering Products

    Delivering Products In the final part of the purchase process, your app waits for the App Store to p ...

随机推荐

  1. iOS release版本去除NSLog打印信息

    因为NSLog的输出还是比较消耗系统资源的,而且输出的数据也可能会暴露出App里的保密数据,所以发布正式版时需要把这些输出全部屏蔽掉. 我们可以在发布版本前先把所有NSLog语句注释掉,等以后要调试时 ...

  2. Spring MVC入门实例

    1.web.xml配置 <?xml version="1.0" encoding="UTF-8"? > <web-app xmlns:xsi= ...

  3. 391. Perfect Rectangle

    最后更新 一刷 16-Jan-2017 这个题我甚至不知道该怎么总结. 难就难在从这个题抽象出一种解法,看了别人的答案和思路= =然而没有归类总结到某种类型,这题相当于背了个题... 简单的说,除了最 ...

  4. springcloud 学习笔记

    ---恢复内容开始--- 1. pom配置 1.1 引入spring boot 依赖 <parent> <groupId>org.springframework.boot< ...

  5. SpringCloud中Rabbitmq的使用

    1.pom配置,添加以来jar包 <dependency> <groupId>org.springframework.cloud</groupId> <art ...

  6. Seven times have I despised my soul 《我曾七次鄙视自己的灵魂》

    <我曾七次鄙视自己的灵魂>,纪伯以“自己的灵魂”为名,看穿人性所共有弱点的一首诗.诗句简单有力发人深省,督促人们拥有更高的精神境界,呼吁人们涤荡自己的灵魂,唾弃丑恶,追求高尚. Seven ...

  7. php新版本号废弃 preg_replace /e 修饰符

    近期serverphp版本号升级到了 5.6  发现出了非常多警告 preg_replace(): The /e modifier is deprecated, use preg_replace_ca ...

  8. 面向对象五大原则_1.单一职责原则&amp;2.里氏替换原则

    单一职责原则:Single Responsibility Principle (SRP) 一个类.仅仅有一个引起它变化的原因.应该仅仅有一个职责.每个职责都是变化的一个轴线.假设一个类有一个以上的职责 ...

  9. mysql 查询正在执行的事务以及等待锁 常用的sql语句

    使用navicat测试学习: 首先使用set autocommit = 0;(取消自动提交,则当执行语句commit或者rollback执行提交事务或者回滚)   在打开一个执行update查询 正在 ...

  10. 利用PHP判断iPhone、iPad、Android、PC设备

    首页那张大图确实是一个比较头疼的问题 在PC上显示是没问题的,可是到手机上就会超出页面一大截,如果做自适应,图片会被强制压缩 无奈只能用wp_is_mobile()函数在手机上隐藏了这张图,可是这函数 ...