PsnBuyGoodsRequest

Processes an update of entitlement in PlayStation network.

The GameSparks platform will update the 'use_count' for an entitlement (by default 'use_count' is 1).

The request will be rejected if entitlement 'use_limit' is 0

GampSparks platform by default will use internally saved PSN user access token

View interactive version here

Request Parameters

Parameter Required Type Description
authorizationCode No string The authorization code obtained from PSN, as described here https://ps4.scedev.net/resources/documents/SDK/latest/NpAuth-Reference/0008.html
currencyCode No string The ISO 4217 currency code representing the real-world currency used for this transaction.
entitlementLabel Yes string Specify the entitlement label of the entitlement to update. (Not an entitlement ID).
redirectUri No string When using the authorization code obtained from PlayStation®4/PlayStation®Vita/PlayStation®3, this is not required.
subUnitPrice No number The price of this purchase
uniqueTransactionByPlayer No boolean If set to true, the transactionId from this receipt will not be globally valdidated, this will mean replays between players are possible.
useCount No number Optional - specify the quantity of the entitlement to use. Default = 1

Response Parameters

A response containing details of the bought items

Parameter Type Description
boughtItems Boughtitem[] A JSON object containing details of the bought items
currenciesAdded JSON An object containing the short code and amount added for each currency
currency1Added number How much currency type 1 was added
currency2Added number How much currency type 2 was added
currency3Added number How much currency type 3 was added
currency4Added number How much currency type 4 was added
currency5Added number How much currency type 5 was added
currency6Added number How much currency type 6 was added
currencyConsumed number For a buy with currency request, how much currency was used
currencyShortCode string For a buy with currency request, the short code of the currency used
currencyType number For a buy with currency request, which currency type was used
invalidItems string[] A list of invalid items for this purchase (if any). This field is populated only for store buys
scriptData ScriptData A JSON Map of any data added either to the Request or the Response by your Cloud Code
transactionIds string[] The list of transactionIds, for this purchase, if they exist. This field is populated only for store buys

Nested types

Boughtitem

A nested object that represents a bought item.

Parameter Type Description
quantity number The quantity of the bought item
shortCode string The short code of the bought item

ScriptData

A collection of arbitrary data that can be added to a message via a Cloud Code script.

Parameter Type Description
myKey string An arbitrary data key
myValue JSON An arbitrary data value.

Error Codes

Key Value Description
verificationError 1 No matching virtual good can be found
verificationError 2 The PSN servers failed to verify the entitlementLabel
verificationError 3 There was an error connecting to the PSN server

Code Samples

C#

    using GameSparks.Api;
    using GameSparks.Api.Requests;
    using GameSparks.Api.Responses;
    ...
    new PsnBuyGoodsRequest()
        .SetAuthorizationCode(authorizationCode)
        .SetCurrencyCode(currencyCode)
        .SetEntitlementLabel(entitlementLabel)
        .SetRedirectUri(redirectUri)
        .SetSubUnitPrice(subUnitPrice)
        .SetUniqueTransactionByPlayer(uniqueTransactionByPlayer)
        .SetUseCount(useCount)
        .Send((response) => {
        GSEnumerable<BuyVirtualGoodResponse._Boughtitem> boughtItems = response.BoughtItems;
        GSData currenciesAdded = response.CurrenciesAdded;
        long? currency1Added = response.Currency1Added;
        long? currency2Added = response.Currency2Added;
        long? currency3Added = response.Currency3Added;
        long? currency4Added = response.Currency4Added;
        long? currency5Added = response.Currency5Added;
        long? currency6Added = response.Currency6Added;
        long? currencyConsumed = response.CurrencyConsumed;
        string currencyShortCode = response.CurrencyShortCode;
        int? currencyType = response.CurrencyType;
        IList<string> invalidItems = response.InvalidItems;
        GSData scriptData = response.ScriptData;
        IList<string> transactionIds = response.TransactionIds;
        });

ActionScript 3

    import com.gamesparks.*;
    import com.gamesparks.api.requests.*;
    import com.gamesparks.api.responses.*;
    import com.gamesparks.api.types.*;
    ...

    gs.getRequestBuilder()
        .createPsnBuyGoodsRequest()
        .setAuthorizationCode(authorizationCode)
        .setCurrencyCode(currencyCode)
        .setEntitlementLabel(entitlementLabel)
        .setRedirectUri(redirectUri)
        .setSubUnitPrice(subUnitPrice)
        .setUniqueTransactionByPlayer(uniqueTransactionByPlayer)
        .setUseCount(useCount)
        .send(function(response:com.gamesparks.api.responses.BuyVirtualGoodResponse):void {
        var boughtItems:Vector.<Boughtitem> = response.getBoughtItems(); 
        var currenciesAdded:Object = response.getCurrenciesAdded(); 
        var currency1Added:Number = response.getCurrency1Added(); 
        var currency2Added:Number = response.getCurrency2Added(); 
        var currency3Added:Number = response.getCurrency3Added(); 
        var currency4Added:Number = response.getCurrency4Added(); 
        var currency5Added:Number = response.getCurrency5Added(); 
        var currency6Added:Number = response.getCurrency6Added(); 
        var currencyConsumed:Number = response.getCurrencyConsumed(); 
        var currencyShortCode:String = response.getCurrencyShortCode(); 
        var currencyType:Number = response.getCurrencyType(); 
        var invalidItems:Vector.<String> = response.getInvalidItems(); 
        var scriptData:ScriptData = response.getScriptData(); 
        var transactionIds:Vector.<String> = response.getTransactionIds(); 
        });

Objective-C

    #import "GS.h"
    #import "GSAPI.h"
    ...
    GSPsnBuyGoodsRequest* request = [[GSPsnBuyGoodsRequest alloc] init];
    [request setAuthorizationCode:authorizationCode;
    [request setCurrencyCode:currencyCode;
    [request setEntitlementLabel:entitlementLabel;
    [request setRedirectUri:redirectUri;
    [request setSubUnitPrice:subUnitPrice;
    [request setUniqueTransactionByPlayer:uniqueTransactionByPlayer;
    [request setUseCount:useCount;
    [request setCallback:^ (GSBuyVirtualGoodResponse* response) {
    NSArray* boughtItems = [response getBoughtItems]; 
    NSDictionary* currenciesAdded = [response getCurrenciesAdded]; 
    NSNumber* currency1Added = [response getCurrency1Added]; 
    NSNumber* currency2Added = [response getCurrency2Added]; 
    NSNumber* currency3Added = [response getCurrency3Added]; 
    NSNumber* currency4Added = [response getCurrency4Added]; 
    NSNumber* currency5Added = [response getCurrency5Added]; 
    NSNumber* currency6Added = [response getCurrency6Added]; 
    NSNumber* currencyConsumed = [response getCurrencyConsumed]; 
    NSString* currencyShortCode = [response getCurrencyShortCode]; 
    NSNumber* currencyType = [response getCurrencyType]; 
    NSArray* invalidItems = [response getInvalidItems]; 
    NSDictionary* scriptData = [response getScriptData]; 
    NSArray* transactionIds = [response getTransactionIds]; 
    }];
    [gs send:request];

C++


    #include <GameSparks/generated/GSRequests.h>
    using namespace GameSparks::Core;
    using namespace GameSparks::Api::Responses;
    using namespace GameSparks::Api::Requests;
    ...

    void PsnBuyGoodsRequest_Response(GS& gsInstance, const BuyVirtualGoodResponse& response) {
    gsstl:vector<Types::Boughtitem*> boughtItems = response.getBoughtItems(); 
    GSData currenciesAdded = response.getCurrenciesAdded(); 
    Optional::t_LongOptional currency1Added = response.getCurrency1Added(); 
    Optional::t_LongOptional currency2Added = response.getCurrency2Added(); 
    Optional::t_LongOptional currency3Added = response.getCurrency3Added(); 
    Optional::t_LongOptional currency4Added = response.getCurrency4Added(); 
    Optional::t_LongOptional currency5Added = response.getCurrency5Added(); 
    Optional::t_LongOptional currency6Added = response.getCurrency6Added(); 
    Optional::t_LongOptional currencyConsumed = response.getCurrencyConsumed(); 
    gsstl::string currencyShortCode = response.getCurrencyShortCode(); 
    Optional::t_LongOptional currencyType = response.getCurrencyType(); 
    gsstl:vector<gsstl::string> invalidItems = response.getInvalidItems(); 
    GSData scriptData = response.getScriptData(); 
    gsstl:vector<gsstl::string> transactionIds = response.getTransactionIds(); 
    }
    ......

    PsnBuyGoodsRequest request(gsInstance);
    request.SetAuthorizationCode(authorizationCode)
    request.SetCurrencyCode(currencyCode)
    request.SetEntitlementLabel(entitlementLabel)
    request.SetRedirectUri(redirectUri)
    request.SetSubUnitPrice(subUnitPrice)
    request.SetUniqueTransactionByPlayer(uniqueTransactionByPlayer)
    request.SetUseCount(useCount)
    request.Send(PsnBuyGoodsRequest_Response);

Java

import com.gamesparks.sdk.api.autogen.GSRequestBuilder.PsnBuyGoodsRequest;
import com.gamesparks.sdk.api.autogen.GSResponseBuilder.BuyVirtualGoodResponse;
import com.gamesparks.sdk.api.autogen.GSTypes.*;
import com.gamesparks.sdk.api.GSEventListener;

...
gs.getRequestBuilder().createPsnBuyGoodsRequest()
    .setAuthorizationCode(authorizationCode)
    .setCurrencyCode(currencyCode)
    .setEntitlementLabel(entitlementLabel)
    .setRedirectUri(redirectUri)
    .setSubUnitPrice(subUnitPrice)
    .setUniqueTransactionByPlayer(uniqueTransactionByPlayer)
    .setUseCount(useCount)
    .send(new GSEventListener<BuyVirtualGoodResponse>() {
        @Override
        public void onEvent(BuyVirtualGoodResponse response) {
            List<Boughtitem> boughtItems = response.getBoughtItems(); 
            GSData currenciesAdded = response.getCurrenciesAdded(); 
            Long currency1Added = response.getCurrency1Added(); 
            Long currency2Added = response.getCurrency2Added(); 
            Long currency3Added = response.getCurrency3Added(); 
            Long currency4Added = response.getCurrency4Added(); 
            Long currency5Added = response.getCurrency5Added(); 
            Long currency6Added = response.getCurrency6Added(); 
            Long currencyConsumed = response.getCurrencyConsumed(); 
            String currencyShortCode = response.getCurrencyShortCode(); 
            Integer currencyType = response.getCurrencyType(); 
            List<String> invalidItems = response.getInvalidItems(); 
            List<String> transactionIds = response.getTransactionIds(); 
        }
    });

Cloud Code


    var request = new SparkRequests.PsnBuyGoodsRequest();
    request.authorizationCode = ...;
    request.currencyCode = ...;
    request.entitlementLabel = ...;
    request.redirectUri = ...;
    request.subUnitPrice = ...;
    request.uniqueTransactionByPlayer = ...;
    request.useCount = ...;
    var response = request.Send();

var boughtItems = response.boughtItems; 
var currenciesAdded = response.currenciesAdded; 
var currency1Added = response.currency1Added; 
var currency2Added = response.currency2Added; 
var currency3Added = response.currency3Added; 
var currency4Added = response.currency4Added; 
var currency5Added = response.currency5Added; 
var currency6Added = response.currency6Added; 
var currencyConsumed = response.currencyConsumed; 
var currencyShortCode = response.currencyShortCode; 
var currencyType = response.currencyType; 
var invalidItems = response.invalidItems; 
var scriptData = response.scriptData; 
var transactionIds = response.transactionIds; 
Did this page help you? Please enter your feedback below.