apple

package
v1.5.106 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2024 License: Apache-2.0 Imports: 15 Imported by: 4

Documentation

Overview

apple 苹果应用内支付SDK(目前仅支持一个校验逻辑--服务端模式)。 整体流程简述:

  1. app从服务端获取待支付订单ID(这个订单ID是自己服务端产生的订单信息)和待付费productId(如果在苹果上配置了多个productId,则需要从服务端拉取自己的商品和苹果商品关联信息,这里的是指在苹果的productId);
  2. app根据productId,发起应用内支付;
  3. app得到支付成功结果,并将支付结果的receipt信息以及第一步的待支付订单ID发回自己的服务端,服务端调用SDK的Verify,得到校验结果(表示该支付信息是否是苹果处理的);
  4. 如果校验成功则表示苹果支付完成,根据第三步传回的订单ID来处理自己的后续业务逻辑;

综上:当使用苹果的应用内支付时,其实是由自己的客户端APP来发起的“支付结果通知”请求来推动业务支付流程的数据流转。 参考文档:https://help.apple.com/app-store-connect/#/devb57be10e7 **注:实际测试时发现校验接口的返回信息和文档介绍的返回信息仅状态码字段可以对应,其他内容基本不匹配,返回信息可以参考client_test.go**

Index

Constants

View Source
const (
	// 通知类型常量
	// https://developer.apple.com/documentation/appstoreservernotifications/notificationtype
	NotificationTypeV2ConsumptionRequest     = "CONSUMPTION_REQUEST"
	NotificationTypeV2DidChangeRenewalPref   = "DID_CHANGE_RENEWAL_PREF"
	NotificationTypeV2DidChangeRenewalStatus = "DID_CHANGE_RENEWAL_STATUS"
	NotificationTypeV2DidFailToRenew         = "DID_FAIL_TO_RENEW"
	NotificationTypeV2DidRenew               = "DID_RENEW"
	NotificationTypeV2Expired                = "EXPIRED"
	NotificationTypeV2GracePeriodExpired     = "GRACE_PERIOD_EXPIRED"
	NotificationTypeV2OfferRedeemed          = "OFFER_REDEEMED"
	NotificationTypeV2PriceIncrease          = "PRICE_INCREASE"
	NotificationTypeV2Refund                 = "REFUND"
	NotificationTypeV2RefundDeclined         = "REFUND_DECLINED"
	NotificationTypeV2RenewalExtended        = "RENEWAL_EXTENDED"
	NotificationTypeV2Revoke                 = "REVOKE"
	NotificationTypeV2Subscribed             = "SUBSCRIBED"

	// 子类型常量
	// https://developer.apple.com/documentation/appstoreservernotifications/subtype
	SubTypeV2InitialBuy        = "INITIAL_BUY"
	SubTypeV2Resubscribe       = "RESUBSCRIBE"
	SubTypeV2Downgrade         = "DOWNGRADE"
	SubTypeV2Upgrade           = "UPGRADE"
	SubTypeV2AutoRenewEnabled  = "AUTO_RENEW_ENABLED"
	SubTypeV2AutoRenewDisabled = "AUTO_RENEW_DISABLED"
	SubTypeV2Voluntary         = "VOLUNTARY"
	SubTypeV2BillingRetry      = "BILLING_RETRY"
	SubTypeV2PriceIncrease     = "PRICE_INCREASE"
	SubTypeV2GracePeriod       = "GRACE_PERIOD"
	SubTypeV2BillingRecovery   = "BILLING_RECOVERY"
	SubTypeV2Pending           = "PENDING"
	SubTypeV2Accepted          = "ACCEPTED"
)
View Source
const (
	// is the URL when testing your app in the sandbox and while your application is in review
	UrlSandbox = "https://sandbox.itunes.apple.com/verifyReceipt"
	// is the URL when your app is live in the App Store
	UrlProd = "https://buy.itunes.apple.com/verifyReceipt"
)

Variables

This section is empty.

Functions

func ExtractClaims added in v1.5.73

func ExtractClaims(signedPayload string, tran jwt.Claims) (err error)

ExtractClaims 解析jws格式数据 signedPayload:jws格式数据 tran:指针类型的结构体,用于接收解析后的数据

func ParseECPrivateKeyFromPEM added in v1.5.87

func ParseECPrivateKeyFromPEM(key []byte) (*ecdsa.PrivateKey, error)

ParseECPrivateKeyFromPEM parses a PEM encoded Elliptic Curve Private Key Structure

Types

type AllSubscriptionStatusesRsp added in v1.5.86

type AllSubscriptionStatusesRsp struct {
	StatusCodeErr
	AppAppleId  int                                `json:"appAppleId"`
	BundleId    string                             `json:"bundleId"`
	Environment string                             `json:"environment"`
	Data        []*SubscriptionGroupIdentifierItem `json:"data"`
}

type Client added in v1.5.95

type Client struct {
	// contains filtered or unexported fields
}

Client AppleClient

func NewClient added in v1.5.95

func NewClient(iss, bid, kid, privateKey string, isProd bool) (client *Client, err error)

NewClient 初始化Apple客户端 iss:issuer ID bid:bundle ID kid:private key ID privateKey:私钥文件读取后的字符串内容 isProd:是否是正式环境

func (*Client) GetAllSubscriptionStatuses added in v1.5.95

func (c *Client) GetAllSubscriptionStatuses(ctx context.Context, transactionId string) (rsp *AllSubscriptionStatusesRsp, err error)

GetAllSubscriptionStatuses Get All Subscription Statuses Doc: https://developer.apple.com/documentation/appstoreserverapi/get_all_subscription_statuses

func (*Client) GetNotificationHistory added in v1.5.95

func (c *Client) GetNotificationHistory(ctx context.Context, paginationToken string, bm gopay.BodyMap) (rsp *NotificationHistoryRsp, err error)

GetNotificationHistory Get Notification History rsp.NotificationHistory[x].SignedPayload use apple.DecodeSignedPayload() to decode Doc: https://developer.apple.com/documentation/appstoreserverapi/get_notification_history

func (*Client) GetRefundHistory added in v1.5.95

func (c *Client) GetRefundHistory(ctx context.Context, transactionId, revision string) (rsp *RefundHistoryRsp, err error)

GetRefundHistory Get Refund History Doc: https://developer.apple.com/documentation/appstoreserverapi/get_refund_history

func (*Client) GetTransactionHistory added in v1.5.95

func (c *Client) GetTransactionHistory(ctx context.Context, transactionId string, bm gopay.BodyMap) (rsp *TransactionHistoryRsp, err error)

GetTransactionHistory Get Transaction History Doc: https://developer.apple.com/documentation/appstoreserverapi/get_transaction_history

func (*Client) GetTransactionInfo added in v1.5.95

func (c *Client) GetTransactionInfo(ctx context.Context, transactionId string) (rsp *TransactionInfoRsp, err error)

GetTransactionInfo Get Transaction Info Doc: https://developer.apple.com/documentation/appstoreserverapi/get_transaction_info

func (*Client) LookUpOrderId added in v1.5.95

func (c *Client) LookUpOrderId(ctx context.Context, orderId string) (rsp *LookUpOrderIdRsp, err error)

LookUpOrderId Look Up Order ID Doc: https://developer.apple.com/documentation/appstoreserverapi/look_up_order_id

func (*Client) SendConsumptionInformation added in v1.5.95

func (c *Client) SendConsumptionInformation(ctx context.Context, transactionId string, bm gopay.BodyMap) (err error)

SendConsumptionInformation Send Consumption Information Doc: https://developer.apple.com/documentation/appstoreserverapi/send_consumption_information

type CustomClaims added in v1.5.95

type CustomClaims struct {
	jwt.Claims
	Iss string `json:"iss"`
	Iat int64  `json:"iat"`
	Exp int64  `json:"exp"`
	Aud string `json:"aud"`
	Bid string `json:"bid"`
}

type Data added in v1.5.73

type Data struct {
	AppAppleID            int    `json:"appAppleId"`
	BundleID              string `json:"bundleId"`
	BundleVersion         string `json:"bundleVersion"`
	Environment           string `json:"environment"`
	SignedRenewalInfo     string `json:"signedRenewalInfo"`
	SignedTransactionInfo string `json:"signedTransactionInfo"`
}

https://developer.apple.com/documentation/appstoreservernotifications/data

type InApp

type InApp struct {
	// The time the App Store refunded a transaction or revoked it from family sharing, in a date-time format similar to the ISO 8601. This field is present only for refunded or revoked transactions.
	CancellationDate string `json:"cancellation_date"`

	// The time the App Store refunded a transaction or revoked it from family sharing, in UNIX epoch time format, in milliseconds. This field is present only for refunded or revoked transactions. Use this time format for processing dates. The time the App Store refunded a transaction or revoked it from family sharing, in UNIX epoch time format, in milliseconds. This field is present only for refunded or revoked transactions. Use this time format for processing dates.
	// https://developer.apple.com/documentation/appstorereceipts/cancellation_date_ms
	CancellationDateTimestamp string `json:"cancellation_date_ms"`

	// The time Apple customer support canceled a transaction, in the Pacific Time zone. This field is only present for refunded transactions.
	CancellationDatePST string `json:"cancellation_date_pst"`

	// The reason for a refunded transaction. When a customer cancels a transaction, the App Store gives them a refund and provides a value for this key. A value of “1” indicates that the customer canceled their transaction due to an actual or perceived issue within your app. A value of “0” indicates that the transaction was canceled for another reason; for example, if the customer made the purchase accidentally.
	// Possible values: 1, 0
	CancellationReason string `json:"cancellation_reason"`

	// The time a subscription expires or when it will renew, in a date-time format similar to the ISO 8601.
	ExpiresDate string `json:"expires_date"`

	// The time a subscription expires or when it will renew, in UNIX epoch time format, in milliseconds. Use this time format for processing dates.
	// https://developer.apple.com/documentation/appstorereceipts/expires_date_ms
	ExpiresDateTimestamp string `json:"expires_date_ms"`

	// The time a subscription expires or when it will renew, in the Pacific Time zone.
	ExpiresDatePST string `json:"expires_date_pst"`

	// An indicator of whether an auto-renewable subscription is in the introductory price period.
	// https://developer.apple.com/documentation/appstorereceipts/is_in_intro_offer_period
	IsInIntroOfferPeriod string `json:"is_in_intro_offer_period"`

	// An indication of whether a subscription is in the free trial period.
	// https://developer.apple.com/documentation/appstorereceipts/is_trial_period
	IsTrialPeriod string `json:"is_trial_period"`

	// The time of the original in-app purchase, in a date-time format similar to ISO 8601.
	OriginalPurchaseDate string `json:"original_purchase_date"`

	// The time of the original in-app purchase, in UNIX epoch time format, in milliseconds. For an auto-renewable subscription, this value indicates the date of the subscription's initial purchase. The original purchase date applies to all product types and remains the same in all transactions for the same product ID. This value corresponds to the original transaction’s transactionDate property in StoreKit. Use this time format for processing dates.
	OriginalPurchaseDateTimestamp string `json:"original_purchase_date_ms"`

	// The time of the original in-app purchase, in the Pacific Time zone.
	OriginalPurchaseDatePST string `json:"original_purchase_date_pst"`

	// The transaction identifier of the original purchase.
	// https://developer.apple.com/documentation/appstorereceipts/original_transaction_id
	OriginalTransactionId string `json:"original_transaction_id"`

	// The unique identifier of the product purchased. You provide this value when creating the product in App Store Connect, and it corresponds to the productIdentifier property of the SKPayment object stored in the transaction's payment property.
	ProductId string `json:"product_id"`

	// The identifier of the subscription offer redeemed by the user.
	// https://developer.apple.com/documentation/appstorereceipts/promotional_offer_id
	PromotionalOfferId string `json:"promotional_offer_id"`

	// The time the App Store charged the user's account for a purchased or restored product, or the time the App Store charged the user’s account for a subscription purchase or renewal after a lapse, in a date-time format similar to ISO 8601.
	PurchaseDate string `json:"purchase_date"`

	// For consumable, non-consumable, and non-renewing subscription products, the time the App Store charged the user's account for a purchased or restored product, in the UNIX epoch time format, in milliseconds. For auto-renewable subscriptions, the time the App Store charged the user’s account for a subscription purchase or renewal after a lapse, in the UNIX epoch time format, in milliseconds. Use this time format for processing dates.
	PurchaseDateTimestamp string `json:"purchase_date_ms"`

	// The time the App Store charged the user's account for a purchased or restored product, or the time the App Store charged the user’s account for a subscription purchase or renewal after a lapse, in the Pacific Time zone.
	PurchaseDatePST string `json:"purchase_date_pst"`

	// The number of consumable products purchased. This value corresponds to the quantity property of the SKPayment object stored in the transaction's payment property. The value is usually “1” unless modified with a mutable payment. The maximum value is 10.
	Quantity string `json:"quantity"`

	// A unique identifier for a transaction such as a purchase, restore, or renewal. See transaction_id for more information.
	TransactionId string `json:"transaction_id"`

	// A unique identifier for purchase events across devices, including subscription-renewal events. This value is the primary key for identifying subscription purchases.
	WebOrderLineItemId string `json:"web_order_line_item_id"`
}

InApp is the in-app purchase receipt fields for all in-app purchase transactions. https://developer.apple.com/documentation/appstorereceipts/responsebody/receipt/in_app

type LastTransactionsItem added in v1.5.86

type LastTransactionsItem struct {
	OriginalTransactionId string `json:"originalTransactionId"`
	Status                int    `json:"status"`
	SignedRenewalInfo     string `json:"signedRenewalInfo"`
	SignedTransactionInfo string `json:"signedTransactionInfo"`
}

func (*LastTransactionsItem) DecodeRenewalInfo added in v1.5.86

func (d *LastTransactionsItem) DecodeRenewalInfo() (ri *RenewalInfo, err error)

func (*LastTransactionsItem) DecodeTransactionInfo added in v1.5.86

func (d *LastTransactionsItem) DecodeTransactionInfo() (ti *TransactionInfo, err error)

type LatestReceiptInfo

type LatestReceiptInfo struct {
	// The time Apple customer support canceled a transaction, in a date-time format similar to the ISO 8601. This field is only present for refunded transactions.
	CancellationDate string `json:"cancellation_date"`

	// The time Apple customer support canceled a transaction, or the time an auto-renewable subscription plan was upgraded, in UNIX epoch time format, in milliseconds. This field is only present for refunded transactions. Use this time format for processing dates.
	// https://developer.apple.com/documentation/appstorereceipts/cancellation_date_ms
	CancellationDateTimestamp string `json:"cancellation_date_ms"`

	// The time Apple customer support canceled a transaction, in the Pacific Time zone. This field is only present for refunded transactions.
	CancellationDatePST string `json:"cancellation_date_pst"`

	// The reason for a refunded transaction. When a customer cancels a transaction, the App Store gives them a refund and provides a value for this key. A value of “1” indicates that the customer canceled their transaction due to an actual or perceived issue within your app. A value of “0” indicates that the transaction was canceled for another reason; for example, if the customer made the purchase accidentally.
	// Possible values: 1, 0
	CancellationReason string `json:"cancellation_reason"`

	// The time a subscription expires or when it will renew, in a date-time format similar to the ISO 8601.
	ExpiresDate string `json:"expires_date"`

	// The time a subscription expires or when it will renew, in UNIX epoch time format, in milliseconds. Use this time format for processing dates.
	// https://developer.apple.com/documentation/appstorereceipts/expires_date_ms
	ExpiresDateTimestamp string `json:"expires_date_ms"`

	// The time a subscription expires or when it will renew, in the Pacific Time zone.
	ExpiresDatePST string `json:"expires_date_pst"`

	// A value that indicates whether the user is the purchaser of the product, or is a family member with access to the product through Family Sharing.
	// https://developer.apple.com/documentation/appstorereceipts/in_app_ownership_type
	InAppOwnershipType string `json:"in_app_ownership_type"`

	// An indicator of whether an auto-renewable subscription is in the introductory price period.
	// Possible values: true, false
	IsInIntroOfferPeriod string `json:"is_in_intro_offer_period"`

	// An indicator of whether a subscription is in the free trial period.
	// https://developer.apple.com/documentation/appstorereceipts/is_trial_period
	IsTrialPeriod string `json:"is_trial_period"`

	// An indicator that a subscription has been canceled due to an upgrade. This field is only present for upgrade transactions.
	// Value: true
	IsUpgraded string `json:"is_upgraded"`

	// The reference name of a subscription offer that you configured in App Store Connect. This field is present when a customer redeemed a subscription offer code. For more information about offer codes
	// https://help.apple.com/app-store-connect/#/dev6a098e4b1
	// https://developer.apple.com/documentation/storekit/original_api_for_in-app_purchase/subscriptions_and_offers/implementing_offer_codes_in_your_app
	OfferCodeRefName string `json:"offer_code_ref_name"`

	// The time of the original app purchase, in a date-time format similar to ISO 8601.
	OriginalPurchaseDate string `json:"original_purchase_date"`

	// The time of the original app purchase, in UNIX epoch time format, in milliseconds. Use this time format for processing dates. For an auto-renewable subscription, this value indicates the date of the subscription’s initial purchase. The original purchase date applies to all product types and remains the same in all transactions for the same product ID. This value corresponds to the original transaction’s transactionDate property in StoreKit.
	OriginalPurchaseDateTimestamp string `json:"original_purchase_date_ms"`

	// The time of the original app purchase, in the Pacific Time zone.
	OriginalPurchaseDatePST string `json:"original_purchase_date_pst"`

	// The transaction identifier of the original purchase.
	// https://developer.apple.com/documentation/appstorereceipts/original_transaction_id
	OriginalTransactionId string `json:"original_transaction_id"`

	// The unique identifier of the product purchased. You provide this value when creating the product in App Store Connect, and it corresponds to the productIdentifier property of the SKPayment object stored in the transaction’s payment property.
	ProductId string `json:"product_id"`

	// The identifier of the subscription offer redeemed by the user.
	// https://developer.apple.com/documentation/appstorereceipts/promotional_offer_id
	PromotionalOfferId string `json:"promotional_offer_id"`

	// The time the App Store charged the user’s account for a purchased or restored product, or the time the App Store charged the user’s account for a subscription purchase or renewal after a lapse, in a date-time format similar to ISO 8601.
	PurchaseDate string `json:"purchase_date"`

	// For consumable, non-consumable, and non-renewing subscription products, the time the App Store charged the user’s account for a purchased or restored product, in the UNIX epoch time format, in milliseconds. For auto-renewable subscriptions, the time the App Store charged the user’s account for a subscription purchase or renewal after a lapse, in the UNIX epoch time format, in milliseconds. Use this time format for processing dates.
	PurchaseDateTimestamp string `json:"purchase_date_ms"`

	// The time the App Store charged the user’s account for a purchased or restored product, or the time the App Store charged the user’s account for a subscription purchase or renewal after a lapse, in the Pacific Time zone.
	PurchaseDatePST string `json:"purchase_date_pst"`

	// The number of consumable products purchased. This value corresponds to the quantity property of the SKPayment object stored in the transaction’s payment property. The value is usually “1” unless modified with a mutable payment. The maximum value is 10.
	Quantity string `json:"quantity"`

	// The identifier of the subscription group to which the subscription belongs. The value for this field is identical to the subscriptionGroupIdentifier property in SKProduct.
	// https://developer.apple.com/documentation/storekit/skproduct/2981047-subscriptiongroupidentifier
	SubscriptionGroupIdentifier string `json:"subscription_group_identifier"`

	// A unique identifier for purchase events across devices, including subscription-renewal events. This value is the primary key for identifying subscription purchases.
	WebOrderLineItemId string `json:"web_order_line_item_id"`

	// A unique identifier for a transaction such as a purchase, restore, or renewal
	TransactionId string `json:"transaction_id"`

	// https://developer.apple.com/documentation/appstorereceipts/app_account_token
	AppAccountToken string `json:"app_account_token"`
}

LatestReceiptInfo https://developer.apple.com/documentation/appstorereceipts/responsebody/latest_receipt_info

type LookUpOrderIdRsp added in v1.5.95

type LookUpOrderIdRsp struct {
	StatusCodeErr
	Status             int                 `json:"status,omitempty"` // 0-valid,1-invalid
	SignedTransactions []SignedTransaction `json:"signedTransactions,omitempty"`
}

type NotificationHistoryRsp added in v1.5.95

type NotificationHistoryRsp struct {
	StatusCodeErr
	HasMore             bool                `json:"hasMore"`
	PaginationToken     string              `json:"paginationToken"`
	NotificationHistory []*NotificationItem `json:"notificationHistory"`
}

type NotificationItem added in v1.5.95

type NotificationItem struct {
	SendAttempts  []*SendAttemptItem `json:"sendAttempts"`
	SignedPayload string             `json:"signedPayload"`
}

type NotificationV2Payload added in v1.5.73

type NotificationV2Payload struct {
	jwt.StandardClaims
	NotificationType string `json:"notificationType"`
	Subtype          string `json:"subtype"`
	NotificationUUID string `json:"notificationUUID"`
	Version          string `json:"version"`
	Data             *Data  `json:"data"`
}

https://developer.apple.com/documentation/appstoreservernotifications/responsebodyv2decodedpayload

func DecodeSignedPayload added in v1.5.73

func DecodeSignedPayload(signedPayload string) (payload *NotificationV2Payload, err error)

DecodeSignedPayload 解析SignedPayload数据

func (*NotificationV2Payload) DecodeRenewalInfo added in v1.5.73

func (d *NotificationV2Payload) DecodeRenewalInfo() (ri *RenewalInfo, err error)

func (*NotificationV2Payload) DecodeTransactionInfo added in v1.5.73

func (d *NotificationV2Payload) DecodeTransactionInfo() (ti *TransactionInfo, err error)

type NotificationV2Req added in v1.5.73

type NotificationV2Req struct {
	SignedPayload string `json:"signedPayload"`
}

https://developer.apple.com/documentation/appstoreservernotifications/responsebodyv2

type PendingRenewalInfo

type PendingRenewalInfo struct {
	// The value for this key corresponds to the productIdentifier property of the product that the customer’s subscription renews.
	AutoRenewProductId string `json:"auto_renew_product_id"`

	// The current renewal status for the auto-renewable subscription.
	// https://developer.apple.com/documentation/appstorereceipts/auto_renew_status
	AutoRenewStatus string `json:"auto_renew_status"`

	// The reason a subscription expired. This field is only present for a receipt that contains an expired auto-renewable subscription.
	// https://developer.apple.com/documentation/appstorereceipts/expiration_intent
	ExpirationIntent string `json:"expiration_intent"`

	// The time at which the grace period for subscription renewals expires, in a date-time format similar to the ISO 8601.
	GracePeriodExpiresDate string `json:"grace_period_expires_date"`

	// The time at which the grace period for subscription renewals expires, in UNIX epoch time format, in milliseconds. This key is only present for apps that have Billing Grace Period enabled and when the user experiences a billing error at the time of renewal. Use this time format for processing dates.
	GracePeriodExpiresDateTimestamp string `json:"grace_period_expires_date_ms"`

	// The time at which the grace period for subscription renewals expires, in the Pacific Time zone.
	GracePeriodExpiresDatePST string `json:"grace_period_expires_date_pst"`

	// A flag that indicates Apple is attempting to renew an expired subscription automatically. This field is only present if an auto-renewable subscription is in the billing retry state.
	// https://developer.apple.com/documentation/appstorereceipts/is_in_billing_retry_period
	IsInBillingRetryPeriod string `json:"is_in_billing_retry_period"`

	// The reference name of a subscription offer that you configured in App Store Connect. This field is present when a customer redeemed a subscription offer code
	// https://developer.apple.com/documentation/appstorereceipts/offer_code_ref_name
	OfferCodeRefName string `json:"offer_code_ref_name"`

	// The transaction identifier of the original purchase.
	OriginalTransactionId string `json:"original_transaction_id"`

	// The price consent status for a subscription price increase. This field is only present if the customer was notified of the price increase. The default value is "0" and changes to "1" if the customer consents.
	// Possible values: 1, 0
	PriceConsentStatus string `json:"price_consent_status"`

	// The unique identifier of the product purchased. You provide this value when creating the product in App Store Connect, and it corresponds to the productIdentifier property of the SKPayment object stored in the transaction's payment property.
	// https://developer.apple.com/documentation/storekit/skpayment
	ProductId string `json:"product_id"`

	// The identifier of the promotional offer for an auto-renewable subscription that the user redeemed. You provide this value in the Promotional Offer Identifier field when you create the promotional offer in App Store Connect.
	// https://developer.apple.com/documentation/appstorereceipts/promotional_offer_id
	Promotionalofferid string `json:"promotional_offer_id"`
}

PendingRenewalInfo https://developer.apple.com/documentation/appstorereceipts/responsebody/pending_renewal_info

type Receipt

type Receipt struct {
	// See app_item_id.
	AdamId int64 `json:"adam_id"`

	// Generated by App Store Connect and used by the App Store to uniquely identify the app purchased. Apps are assigned this identifier only in production. Treat this value as a 64-bit long integer.
	AppItemId int64 `json:"app_item_id"`

	// The app’s version number. The app's version number corresponds to the value of CFBundleVersion (in iOS) or CFBundleShortVersionString (in macOS) in the Info.plist. In production, this value is the current version of the app on the device based on the receipt_creation_date_ms. In the sandbox, the value is always "1.0".
	ApplicationVersion string `json:"application_version"`

	// The bundle identifier for the app to which the receipt belongs. You provide this string on App Store Connect. This corresponds to the value of CFBundleIdentifier in the Info.plist file of the app.
	BundleId string `json:"bundle_id"`

	// A unique identifier for the app download transaction.
	DownloadId int64 `json:"download_id"`

	// The time the receipt expires for apps purchased through the Volume Purchase Program, in a date-time format similar to the ISO 8601.
	ExpirationDate string `json:"expiration_date"`

	// The time the receipt expires for apps purchased through the Volume Purchase Program, in UNIX epoch time format, in milliseconds. If this key is not present for apps purchased through the Volume Purchase Program, the receipt does not expire. Use this time format for processing dates.
	ExpirationDateTimestamp string `json:"expiration_date_ms"`

	// The time the receipt expires for apps purchased through the Volume Purchase Program, in the Pacific Time zone.
	ExpirationDatePST string `json:"expiration_date_pst"`

	// An array that contains the in-app purchase receipt fields for all in-app purchase transactions.
	InApp []*InApp `json:"in_app,omitempty"`

	// The version of the app that the user originally purchased. This value does not change, and corresponds to the value of CFBundleVersion (in iOS) or CFBundleShortVersionString (in macOS) in the Info.plist file of the original purchase. In the sandbox environment, the value is always "1.0".
	OriginalApplicationVersion string `json:"original_application_version"`

	// The time of the original app purchase, in a date-time format similar to ISO 8601.
	OriginalPurchaseDate string `json:"original_purchase_date"`

	// The time of the original app purchase, in UNIX epoch time format, in milliseconds. Use this time format for processing dates.
	OriginalPurchaseDateTimestamp string `json:"original_purchase_date_ms"`

	// The time of the original app purchase, in the Pacific Time zone.
	OriginalPurchaseDatePST string `json:"original_purchase_date_pst"`

	// The time the user ordered the app available for pre-order, in a date-time format similar to ISO 8601.
	PreorderDate string `json:"preorder_date"`

	// The time the user ordered the app available for pre-order, in UNIX epoch time format, in milliseconds. This field is only present if the user pre-orders the app. Use this time format for processing dates.
	PreorderDateTimestamp string `json:"preorder_date_ms"`

	// The time the user ordered the app available for pre-order, in the Pacific Time zone.
	PreorderDatePST string `json:"preorder_date_pst"`

	// The time the App Store generated the receipt, in a date-time format similar to ISO 8601.
	ReceiptCreationDate string `json:"receipt_creation_date"`

	// The time the App Store generated the receipt, in UNIX epoch time format, in milliseconds. Use this time format for processing dates. This value does not change.
	ReceiptCreationDateTimestamp string `json:"receipt_creation_date_ms"`

	// The time the App Store generated the receipt, in the Pacific Time zone.
	ReceiptCreationDatePST string `json:"receipt_creation_date_pst"`

	// The type of receipt generated. The value corresponds to the environment in which the app or VPP purchase was made.
	//  Possible values: Production, ProductionVPP, ProductionSandbox, ProductionVPPSandbox
	ReceiptType string `json:"receipt_type"`

	// The time the request to the verifyReceipt endpoint was processed and the response was generated, in a date-time format similar to ISO 8601.
	RequestDate string `json:"request_date"`

	// The time the request to the verifyReceipt endpoint was processed and the response was generated, in UNIX epoch time format, in milliseconds. Use this time format for processing dates.
	RequestDateTimestamp string `json:"request_date_ms"`

	// The time the request to the verifyReceipt endpoint was processed and the response was generated, in the Pacific Time zone.
	RequestDatePST string `json:"request_date_pst"`

	// An arbitrary number that identifies a revision of your app. In the sandbox, this key's value is 0.
	VersionExternalIdentifier int64 `json:"version_external_identifier"`
}

Receipt is the decoded version of the encoded receipt data sent with the request to the App Store https://developer.apple.com/documentation/appstorereceipts/responsebody/receipt

type RefundHistoryRsp added in v1.5.95

type RefundHistoryRsp struct {
	StatusCodeErr
	HasMore            bool                `json:"hasMore"`
	Revision           string              `json:"revision"`
	SignedTransactions []SignedTransaction `json:"signedTransactions"`
}

type RenewalInfo added in v1.5.73

type RenewalInfo struct {
	jwt.StandardClaims
	AutoRenewProductId          string `json:"autoRenewProductId"`
	AutoRenewStatus             int64  `json:"autoRenewStatus"`
	Environment                 string `json:"environment"`
	ExpirationIntent            int64  `json:"expirationIntent"`
	GracePeriodExpiresDate      int64  `json:"gracePeriodExpiresDate"`
	IsInBillingRetryPeriod      bool   `json:"isInBillingRetryPeriod"`
	OfferIdentifier             string `json:"offerIdentifier"`
	OfferType                   int64  `json:"offerType"` // 1:An introductory offer. 2:A promotional offer. 3:An offer with a subscription offer code.
	OriginalTransactionId       string `json:"originalTransactionId"`
	PriceIncreaseStatus         int64  `json:"priceIncreaseStatus"` // 0: The customer hasn’t responded to the subscription price increase. 1:The customer consented to the subscription price increase.
	ProductId                   string `json:"productId"`
	RecentSubscriptionStartDate int64  `json:"recentSubscriptionStartDate"`
	RenewalDate                 int64  `json:"renewalDate,omitempty"` // The UNIX time, in milliseconds, that the most recent auto-renewable subscription purchase expires.
	SignedDate                  int64  `json:"signedDate"`
}

RenewalInfo https://developer.apple.com/documentation/appstoreservernotifications/jwsrenewalinfodecodedpayload

type SendAttemptItem added in v1.5.95

type SendAttemptItem struct {
	AttemptDate       int64  `json:"attemptDate"`
	SendAttemptResult string `json:"sendAttemptResult"`
}

type SignedTransaction added in v1.5.87

type SignedTransaction string

func (*SignedTransaction) DecodeSignedTransaction added in v1.5.87

func (s *SignedTransaction) DecodeSignedTransaction() (ti *TransactionsItem, err error)

type StatusCodeErr added in v1.5.95

type StatusCodeErr struct {
	ErrorCode    int    `json:"errorCode,omitempty"`
	ErrorMessage string `json:"errorMessage,omitempty"`
}

StatusCodeErr 用于判断Apple的status_code错误

func IsStatusCodeError added in v1.5.95

func IsStatusCodeError(err error) (*StatusCodeErr, bool)

func (*StatusCodeErr) Error added in v1.5.95

func (e *StatusCodeErr) Error() string

type SubscriptionGroupIdentifierItem added in v1.5.86

type SubscriptionGroupIdentifierItem struct {
	SubscriptionGroupIdentifier string                  `json:"subscriptionGroupIdentifier"`
	LastTransactions            []*LastTransactionsItem `json:"lastTransactions"`
}

type TransactionHistoryRsp added in v1.5.86

type TransactionHistoryRsp struct {
	StatusCodeErr
	AppAppleId         int                 `json:"appAppleId"`
	BundleId           string              `json:"bundleId"`
	Environment        string              `json:"environment"`
	HasMore            bool                `json:"hasMore"`
	Revision           string              `json:"revision"`
	SignedTransactions []SignedTransaction `json:"signedTransactions"`
}

Doc: HistoryResponse https://developer.apple.com/documentation/appstoreserverapi/historyresponse

type TransactionInfo added in v1.5.73

type TransactionInfo struct {
	jwt.StandardClaims
	AppAccountToken             string `json:"appAccountToken"`
	BundleId                    string `json:"bundleId"`
	Currency                    string `json:"currency"`
	Environment                 string `json:"environment"`
	ExpiresDate                 int64  `json:"expiresDate"`
	InAppOwnershipType          string `json:"inAppOwnershipType"` // FAMILY_SHARED  PURCHASED
	IsUpgraded                  bool   `json:"isUpgraded"`
	OfferDiscountType           string `json:"offerDiscountType"`
	OfferIdentifier             string `json:"offerIdentifier"`
	OfferType                   int64  `json:"offerType"` // 1:An introductory offer. 2:A promotional offer. 3:An offer with a subscription offer code.
	OriginalPurchaseDate        int64  `json:"originalPurchaseDate"`
	OriginalTransactionId       string `json:"originalTransactionId"`
	Price                       int64  `json:"price"`
	ProductId                   string `json:"productId"`
	PurchaseDate                int64  `json:"purchaseDate"`
	Quantity                    int64  `json:"quantity"`
	RevocationDate              int64  `json:"revocationDate"`
	RevocationReason            int    `json:"revocationReason"`
	SignedDate                  int64  `json:"signedDate"` // Auto-Renewable Subscription: An auto-renewable subscription.  Non-Consumable: A non-consumable in-app purchase.  Consumable: A consumable in-app purchase.  Non-Renewing Subscription: A non-renewing subcription.
	Storefront                  string `json:"storefront"`
	StorefrontId                string `json:"storefrontId"`
	SubscriptionGroupIdentifier string `json:"subscriptionGroupIdentifier"`
	TransactionId               string `json:"transactionId"`
	TransactionReason           string `json:"transactionReason"`
	Type                        string `json:"type"`
	WebOrderLineItemId          string `json:"webOrderLineItemId"`
}

TransactionInfo https://developer.apple.com/documentation/appstoreservernotifications/jwstransactiondecodedpayload

type TransactionInfoRsp added in v1.5.95

type TransactionInfoRsp struct {
	StatusCodeErr
	SignedTransactionInfo string `json:"signedTransactionInfo"`
}

Doc: https://developer.apple.com/documentation/appstoreserverapi/transactioninforesponse

func (*TransactionInfoRsp) DecodeSignedTransaction added in v1.5.95

func (t *TransactionInfoRsp) DecodeSignedTransaction() (ti *TransactionsItem, err error)

type TransactionsItem added in v1.5.87

type TransactionsItem struct {
	jwt.StandardClaims
	AppAccountToken             string `json:"appAccountToken"`
	BundleId                    string `json:"bundleId"`
	Currency                    string `json:"currency"`
	Environment                 string `json:"environment"`
	ExpiresDate                 int64  `json:"expiresDate"`
	InAppOwnershipType          string `json:"inAppOwnershipType"`
	IsUpgraded                  bool   `json:"isUpgraded"`
	OfferDiscountType           string `json:"offerDiscountType"`
	OfferIdentifier             string `json:"offerIdentifier"`
	OfferType                   int    `json:"offerType"`
	OriginalPurchaseDate        int64  `json:"originalPurchaseDate"`
	OriginalTransactionId       string `json:"originalTransactionId"`
	Price                       int64  `json:"price"`
	ProductId                   string `json:"productId"`
	PurchaseDate                int64  `json:"purchaseDate"`
	Quantity                    int    `json:"quantity"`
	RevocationDate              int64  `json:"revocationDate"`
	RevocationReason            int    `json:"revocationReason"`
	SignedDate                  int64  `json:"signedDate"`
	Storefront                  string `json:"storefront"`
	StorefrontId                string `json:"storefrontId"`
	SubscriptionGroupIdentifier string `json:"subscriptionGroupIdentifier"`
	TransactionId               string `json:"transactionId"`
	TransactionReason           string `json:"transactionReason"`
	Type                        string `json:"type"`
	WebOrderLineItemId          string `json:"webOrderLineItemId"`
}

TransactionsItem Doc: https://developer.apple.com/documentation/appstoreserverapi/jwstransactiondecodedpayload

type VerifyRequest

type VerifyRequest struct {
	// Receipt app解析出的票据信息
	Receipt string `json:"receipt-data"`

	// Password App的秘钥
	Password string `json:"password,omitempty"`

	// ExcludeOldTranscations Set this value to true for the response to include only the latest renewal transaction for any subscriptions. Use this field only for app receipts that contain auto-renewable subscriptions.
	ExcludeOldTranscations bool `json:"exclude-old-transactions,omitempty"`
}

VerifyRequest 校验请求体 https://developer.apple.com/documentation/appstorereceipts/requestbody

type VerifyResponse

type VerifyResponse struct {
	// Environment is which the receipt was generated. Possible values: Sandbox, Production
	Environment string `json:"environment"`

	// IsRetryable is an indicator that an error occurred during the request. A value of 1 indicates a temporary issue; retry validation for this receipt at a later time. A value of 0 indicates an unresolvable issue; do not retry validation for this receipt. Only applicable to status codes 21100-21199.
	IsRetryable bool `json:"is-retryable"`

	// LatestReceipt The latest Base64 encoded app receipt. Only returned for receipts that contain auto-renewable subscriptions
	LatestReceipt string `json:"latest_receipt,omitempty"`

	// LatestReceiptInfo is an array that contains all in-app purchase transactions. This excludes transactions for consumable products that have been marked as finished by your app. Only returned for receipts that contain auto-renewable subscriptions.
	LatestReceiptInfo []*LatestReceiptInfo `json:"latest_receipt_info,omitempty"`

	// PendingRenewalInfo ,in the JSON file, an array where each element contains the pending renewal information for each auto-renewable subscription identified by the product_id. Only returned for app receipts that contain auto-renewable subscriptions.
	PendingRenewalInfo []*PendingRenewalInfo `json:"pending_renewal_info,omitempty"`

	// Receipt is a JSON representation of the receipt that was sent for verification.
	Receipt *Receipt `json:"receipt,omitempty"`

	// Status either 0 if the receipt is valid, or a status code if there is an error. The status code reflects the status of the app receipt as a whole. See status for possible status codes and descriptions.
	// =0时就表示校验成功
	Status int `json:"status"`
}

VerifyResponse 校验响应体 https://developer.apple.com/documentation/appstorereceipts/responsebody

func VerifyReceipt

func VerifyReceipt(ctx context.Context, url, pwd, receipt string) (rsp *VerifyResponse, err error)

VerifyReceipt 请求APP Store 校验支付请求,实际测试时发现这个文档介绍的返回信息只有那个status==0表示成功可以用,其他的返回信息跟文档对不上 url:取 UrlProd 或 UrlSandbox pwd:苹果APP秘钥,https://help.apple.com/app-store-connect/#/devf341c0f01 文档:https://developer.apple.com/documentation/appstorereceipts/verifyreceipt

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL