IAP 라이브러리 추가 from kd-branch
This commit is contained in:
110
iap/galaxystore.go
Normal file
110
iap/galaxystore.go
Normal file
@ -0,0 +1,110 @@
|
||||
package iap
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type GalaxyStoreIAPVerifier struct {
|
||||
ItemId string `json:"itemId"`
|
||||
PaymentId string `json:"paymentId"`
|
||||
OrderId string `json:"orderId"`
|
||||
PackageName string `json:"packageName"`
|
||||
ItemName string `json:"itemName"`
|
||||
ItemDesc string `json:"itemDesc"`
|
||||
PurchaseDate string `json:"purchaseDate"`
|
||||
PaymentAmount string `json:"paymentAmount"`
|
||||
Status string `json:"status"`
|
||||
PaymentMethod string `json:"paymentMethod"`
|
||||
Mode string `json:"mode"`
|
||||
ConsumeYN string `json:"consumeYN"`
|
||||
ConsumeDate string `json:"consumeDate"`
|
||||
ConsumeDeviceModel string `json:"consumeDeviceModel"`
|
||||
PassThroughParam string `json:"passThroughParam"`
|
||||
CurrencyCode string `json:"currencyCode"`
|
||||
CurrencyUnit string `json:"currencyUnit"`
|
||||
VerificationLog string
|
||||
}
|
||||
|
||||
func (verifer *GalaxyStoreIAPVerifier) Verify(purchaseId string, paymentId string, developerPayload string, itemId string, packageName string) (bool, error) {
|
||||
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest("GET", "https://iap.samsungapps.com/iap/v6/receipt?purchaseID="+purchaseId, nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
json.Unmarshal(body, verifer)
|
||||
|
||||
verifer.VerificationLog = string(body)
|
||||
|
||||
if verifer.Status != "success" {
|
||||
return false, errors.New("Status is wrong:" + verifer.Status)
|
||||
}
|
||||
|
||||
if verifer.ItemId != itemId {
|
||||
return false, errors.New("itemId is different")
|
||||
}
|
||||
|
||||
if verifer.PackageName != packageName {
|
||||
return false, errors.New("packageName is different")
|
||||
}
|
||||
|
||||
if !strings.EqualFold(verifer.PassThroughParam, developerPayload) {
|
||||
return false, errors.New("developerPayload is different : " + verifer.PassThroughParam + "/" + developerPayload)
|
||||
}
|
||||
|
||||
if verifer.PaymentId != paymentId {
|
||||
return false, errors.New("paymentId is different")
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// Owned Item - mItemId: kd_currency_gold_75
|
||||
// Owned Item - mItemName: Gold x75
|
||||
// Owned Item - mItemPrice: 1300.000000
|
||||
// Owned Item - mItemPriceString: ₩1,300
|
||||
// Owned Item - mCurrencyUnit: ₩
|
||||
// Owned Item - mCurrencyCode: KRW
|
||||
// Owned Item - mItemDesc: 75 Gold
|
||||
// Owned Item - mPaymentId: TPMTID20240208KR32371566
|
||||
// Owned Item - mPurchaseId: 34c50c9677e8e837e7b7a6eaac37a385fb7e4b36437820825bc7d824647c6aa7
|
||||
// Owned Item - mPurchaseDate: -2147483648
|
||||
// Owned Item - mPassThroughParam: testpayload
|
||||
|
||||
// {
|
||||
// "itemId": "kd_currency_gold_75",
|
||||
// "paymentId": "TPMTID20240208KR32367386",
|
||||
// "orderId": "P20240208KR32367386",
|
||||
// "packageName": "com.yjmgames.kingdom.gal",
|
||||
// "itemName": "Gold x75",
|
||||
// "itemDesc": "75 Gold",
|
||||
// "purchaseDate": "2024-02-08 02:33:24",
|
||||
// "paymentAmount": "1300.0",
|
||||
// "status": "success",
|
||||
// "paymentMethod": "Credit Card",
|
||||
// "mode": "TEST",
|
||||
// "consumeYN": "Y",
|
||||
// "consumeDate": "2024-02-08 02:52:10",
|
||||
// "consumeDeviceModel": "SM-S918N",
|
||||
// "passThroughParam": "testpayload",
|
||||
// "currencyCode": "KRW",
|
||||
// "currencyUnit": "₩"
|
||||
// }
|
||||
Reference in New Issue
Block a user