Documentation
¶
Index ¶
- Constants
- func HandleError(status int) error
- type CancellationDate
- type Client
- type Environment
- type ExpiresDate
- type IAPClient
- type IAPRequest
- type IAPResponse
- type IAPResponseForIOS6
- type InApp
- type NotificationEnvironment
- type NotificationExpiresDate
- type NotificationReceipt
- type NotificationType
- type OriginalPurchaseDate
- type PendingRenewalInfo
- type PurchaseDate
- type Receipt
- type ReceiptCreationDate
- type ReceiptForIOS6
- type RequestDate
- type StatusResponse
- type SubscriptionNotification
Constants ¶
const ( // SandboxURL is the endpoint for sandbox environment. SandboxURL string = "https://sandbox.itunes.apple.com/verifyReceipt" // ProductionURL is the endpoint for production environment. ProductionURL string = "https://buy.itunes.apple.com/verifyReceipt" // ContentType is the request content-type for apple store. ContentType string = "application/json; charset=utf-8" )
Variables ¶
This section is empty.
Functions ¶
func HandleError ¶
HandleError returns error message by status code
Types ¶
type CancellationDate ¶
type CancellationDate struct {
CancellationDate string `json:"cancellation_date,omitempty"`
CancellationDateMS string `json:"cancellation_date_ms,omitempty"`
CancellationDatePST string `json:"cancellation_date_pst,omitempty"`
}
The CancellationDate type indicates the time and date of the cancellation by Apple customer support
type Client ¶
type Client struct {
ProductionURL string
SandboxURL string
// contains filtered or unexported fields
}
Client implements IAPClient
func NewWithClient ¶
NewWithClient creates a client with a custom http client.
type Environment ¶
type Environment string
const ( Sandbox Environment = "Sandbox" Production Environment = "Production" )
type ExpiresDate ¶
type ExpiresDate struct {
ExpiresDate string `json:"expires_date,omitempty"`
ExpiresDateMS string `json:"expires_date_ms,omitempty"`
ExpiresDatePST string `json:"expires_date_pst,omitempty"`
ExpiresDateFormatted string `json:"expires_date_formatted,omitempty"`
ExpiresDateFormattedPST string `json:"expires_date_formatted_pst,omitempty"`
}
The ExpiresDate type indicates the expiration date for the subscription
type IAPClient ¶
type IAPClient interface {
Verify(ctx context.Context, reqBody IAPRequest, resp interface{}) error
}
IAPClient is an interface to call validation API in App Store
type IAPRequest ¶
type IAPRequest struct {
ReceiptData string `json:"receipt-data"`
// Only used for receipts that contain auto-renewable subscriptions.
Password string `json:"password,omitempty"`
// Only used for iOS7 style app receipts that contain auto-renewable or non-renewing subscriptions.
// If value is true, response includes only the latest renewal transaction for any subscriptions.
ExcludeOldTransactions bool `json:"exclude-old-transactions"`
}
https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html The IAPRequest type has the request parameter
type IAPResponse ¶
type IAPResponse struct {
Status int `json:"status"`
Environment Environment `json:"environment"`
Receipt Receipt `json:"receipt"`
LatestReceiptInfo []InApp `json:"latest_receipt_info,omitempty"`
LatestReceipt string `json:"latest_receipt,omitempty"`
PendingRenewalInfo []PendingRenewalInfo `json:"pending_renewal_info,omitempty"`
IsRetryable bool `json:"is-retryable,omitempty"`
}
The IAPResponse type has the response properties We defined each field by the current IAP response, but some fields are not mentioned in the following Apple's document; https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html If you get other types or fields from the IAP response, you should use the struct you defined.
type IAPResponseForIOS6 ¶
type IAPResponseForIOS6 struct {
AutoRenewProductID string `json:"auto_renew_product_id"`
AutoRenewStatus int `json:"auto_renew_status"`
CancellationReason string `json:"cancellation_reason,omitempty"`
ExpirationIntent string `json:"expiration_intent,omitempty"`
IsInBillingRetryPeriod string `json:"is_in_billing_retry_period,omitempty"`
LatestReceiptInfo ReceiptForIOS6 `json:"latest_expired_receipt_info"`
Receipt ReceiptForIOS6 `json:"receipt"`
Status int `json:"status"`
}
IAPResponseForIOS6 is iOS 6 style receipt schema.
type InApp ¶
type InApp struct {
Quantity string `json:"quantity"`
ProductID string `json:"product_id"`
TransactionID string `json:"transaction_id"`
OriginalTransactionID string `json:"original_transaction_id"`
WebOrderLineItemID string `json:"web_order_line_item_id,omitempty"`
IsTrialPeriod string `json:"is_trial_period"`
IsInIntroOfferPeriod string `json:"is_in_intro_offer_period,omitempty"`
ExpiresDate
PurchaseDate
OriginalPurchaseDate
CancellationDate
CancellationReason string `json:"cancellation_reason,omitempty"`
}
The InApp type has the receipt attributes
type NotificationEnvironment ¶
type NotificationEnvironment string
const ( NotificationSandbox NotificationEnvironment = "Sandbox" NotificationProduction NotificationEnvironment = "PROD" )
type NotificationExpiresDate ¶
type NotificationReceipt ¶
type NotificationReceipt struct {
UniqueIdentifier string `json:"unique_identifier"`
AppItemID string `json:"app_item_id"`
Quantity string `json:"quantity"`
VersionExternalIdentifier string `json:"version_external_identifier"`
UniqueVendorIdentifier string `json:"unique_vendor_identifier"`
WebOrderLineItemID string `json:"web_order_line_item_id"`
ItemID string `json:"item_id"`
ProductID string `json:"product_id"`
BID string `json:"bid"`
BVRS string `json:"bvrs"`
TransactionID string `json:"transaction_id"`
OriginalTransactionID string `json:"original_transaction_id"`
IsTrialPeriod string `json:"is_trial_period"`
IsInIntroOfferPeriod string `json:"is_in_intro_offer_period"`
PurchaseDate
OriginalPurchaseDate
NotificationExpiresDate
CancellationDate
}
type NotificationType ¶
type NotificationType string
const ( // Initial purchase of the subscription. NotificationTypeInitialBuy NotificationType = "INITIAL_BUY" // Subscription was canceled by Apple customer support. NotificationTypeCancel NotificationType = "CANCEL" // Automatic renewal was successful for an expired subscription. NotificationTypeRenewal NotificationType = "RENEWAL" // Customer renewed a subscription interactively after it lapsed. NotificationTypeInteractiveRenewal NotificationType = "INTERACTIVE_RENEWAL" // Customer changed the plan that takes affect at the next subscription renewal. Current active plan is not affected. NotificationTypeDidChangeRenewalPreference NotificationType = "DID_CHANGE_RENEWAL_PREF" // Customer changed the subscription renewal status. Current active plan is not affected. NotificationTypeDidChangeRenewalStatus NotificationType = "DID_CHANGE_RENEWAL_STATUS" )
type OriginalPurchaseDate ¶
type OriginalPurchaseDate struct {
OriginalPurchaseDate string `json:"original_purchase_date"`
OriginalPurchaseDateMS string `json:"original_purchase_date_ms"`
OriginalPurchaseDatePST string `json:"original_purchase_date_pst"`
}
The OriginalPurchaseDate type indicates the beginning of the subscription period
type PendingRenewalInfo ¶
type PendingRenewalInfo struct {
SubscriptionExpirationIntent string `json:"expiration_intent"`
SubscriptionAutoRenewProductID string `json:"auto_renew_product_id"`
SubscriptionRetryFlag string `json:"is_in_billing_retry_period"`
SubscriptionAutoRenewStatus string `json:"auto_renew_status"`
SubscriptionPriceConsentStatus string `json:"price_consent_status"`
ProductID string `json:"product_id"`
OriginalTransactionID string `json:"original_transaction_id"`
}
A pending renewal may refer to a renewal that is scheduled in the future or a renewal that failed in the past for some reason.
type PurchaseDate ¶
type PurchaseDate struct {
PurchaseDate string `json:"purchase_date"`
PurchaseDateMS string `json:"purchase_date_ms"`
PurchaseDatePST string `json:"purchase_date_pst"`
}
The PurchaseDate type indicates the date and time that the item was purchased
type Receipt ¶
type Receipt struct {
ReceiptType string `json:"receipt_type"`
AdamID int64 `json:"adam_id"`
AppItemID numericString `json:"app_item_id"`
BundleID string `json:"bundle_id"`
ApplicationVersion string `json:"application_version"`
DownloadID int64 `json:"download_id"`
VersionExternalIdentifier numericString `json:"version_external_identifier"`
OriginalApplicationVersion string `json:"original_application_version"`
InApp []InApp `json:"in_app"`
ReceiptCreationDate
RequestDate
OriginalPurchaseDate
}
The Receipt type has whole data of receipt
type ReceiptCreationDate ¶
type ReceiptCreationDate struct {
CreationDate string `json:"receipt_creation_date"`
CreationDateMS string `json:"receipt_creation_date_ms"`
CreationDatePST string `json:"receipt_creation_date_pst"`
}
The ReceiptCreationDate type indicates the date when the app receipt was created.
type ReceiptForIOS6 ¶
type ReceiptForIOS6 struct {
AppItemID numericString `json:"app_item_id"`
BID string `json:"bid"`
BVRS string `json:"bvrs"`
CancellationDate
ExpiresDate
IsTrialPeriod string `json:"is_trial_period"`
IsInIntroOfferPeriod string `json:"is_in_intro_offer_period"`
ItemID string `json:"item_id"`
ProductID string `json:"product_id"`
PurchaseDate
OriginalTransactionID string `json:"original_transaction_id"`
OriginalPurchaseDate
Quantity string `json:"quantity"`
TransactionID string `json:"transaction_id"`
UniqueIdentifier string `json:"unique_identifier"`
UniqueVendorIdentifier string `json:"unique_vendor_identifier"`
VersionExternalIdentifier numericString `json:"version_external_identifier,omitempty"`
WebOrderLineItemID string `json:"web_order_line_item_id"`
}
type RequestDate ¶
type RequestDate struct {
RequestDate string `json:"request_date"`
RequestDateMS string `json:"request_date_ms"`
RequestDatePST string `json:"request_date_pst"`
}
The RequestDate type indicates the date and time that the request was sent
type StatusResponse ¶
type StatusResponse struct {
Status int `json:"status"`
}
The HttpStatusResponse struct contains the status code returned by the store Used as a workaround to detect when to hit the production appstore or sandbox appstore regardless of receipt type
type SubscriptionNotification ¶
type SubscriptionNotification struct {
Environment NotificationEnvironment `json:"environment"`
NotificationType NotificationType `json:"notification_type"`
// Not show in raw notify body
Password string `json:"password"`
OriginalTransactionID string `json:"original_transaction_id"`
AutoRenewAdamID string `json:"auto_renew_adam_id"`
// The primary key for identifying a subscription purchase.
// Posted only if the notification_type is CANCEL.
WebOrderLineItemID string `json:"web_order_line_item_id"`
// This is the same as the Subscription Expiration Intent in the receipt.
// Posted only if notification_type is RENEWAL or INTERACTIVE_RENEWAL.
ExpirationIntent string `json:"expiration_intent"`
// Auto renew info
AutoRenewStatus string `json:"auto_renew_status"` // false or true
AutoRenewProductID string `json:"auto_renew_product_id"`
// Posted if the notification_type is RENEWAL or INTERACTIVE_RENEWAL, and only if the renewal is successful.
// Posted also if the notification_type is INITIAL_BUY.
// Not posted for notification_type CANCEL.
LatestReceipt string `json:"latest_receipt"`
LatestReceiptInfo NotificationReceipt `json:"latest_receipt_info"`
// Posted only if the notification_type is RENEWAL or CANCEL or if renewal failed and subscription expired.
LatestExpiredReceipt string `json:"latest_expired_receipt"`
LatestExpiredReceiptInfo NotificationReceipt `json:"latest_expired_receipt_info"`
// Posted only if the notification_type is CANCEL.
CancellationDate
}