# Purchases from iOS in-app messages

To let your users make purchases right from the in-app messages displayed in your iOS app, you can implement the out-of-the-box solution for your Rich Medias and add callbacks to get more info about in-app purchases. 

<Aside>
Available for the **6.4.5 iOS SDK version and further**.
</Aside>

## Rich Media JavaScript implementation

To implement in-app purchases in your Rich Medias, use a simple **JavaScript function call**:

```javascript
pushwooshImpl.makePurchaseWithIdentifier("Premium"); // product identifier specified in your App Store product information
```

## AppDelegate methods for callbacks

If you need callbacks to be executed on a purchase, implement the **PWPurchaseDelegate protocol** as follows: 

1\. Make your project’s AppDelegate conform to the PWPurchaseDelegate protocol:

```objective-c
@interface AppDelegate : PWAppDelegate <PushNotificationDelegate, PWPurchaseDelegate>
```

2\. Implement methods of PWPurchaseDelegate in your AppDelegate:

```objective-c
#pragma mark - Purchase delegate methods
- (void) onPWInAppPurchaseHelperPaymentComplete:(NSString*) identifier {
    NSLog(@“Custom purchase delegate -- payment complete for identifier: %@“, identifier);
}
-(void)onPWInAppPurchaseHelperProducts:(NSArray<SKProduct *>* _Nullable)products {
    NSLog(@“Custom purchase delegate -- retrieved list of products”);
}
-(void)onPWInAppPurchaseHelperPaymentFailedProductIdentifier:(NSString* _Nullable)identifier error:(NSError* _Nullable)error {
    NSLog(@“Custom purchase delegate -- payment failed with identifier %@ and error %@“, identifier, error.description);
}
```

### List of available PWPurchaseDelegate methods

#### List of products

```objective-c
@protocol PWPurchaseDelegate <NSObject>
// Detailed information about list of products in your app 
-(void)onPWInAppPurchaseHelperProducts:(NSArray<SKProduct *>* _Nullable)products;
@end
```

#### Successful transaction

```objective-c
@protocol PWPurchaseDelegate &#x3C;NSObject>
// A successfully processed transaction 
<strong>-(void)onPWInAppPurchaseHelperPaymentComplete:(NSString* _Nullable)identifier;
</strong>
@end
```

#### Failed transaction

```objective-c
@protocol PWPurchaseDelegate &#x3C;NSObject>
<strong>// A failed transaction 
</strong>-(void)onPWInAppPurchaseHelperPaymentFailedProductIdentifier:(NSString* _Nullable)identifier error:(NSError* _Nullable)error;
@end
```

#### Promoted from App Store

```objective-c
@protocol PWPurchaseDelegate <NSObject>
// An in-app purchase is initiated from the App Store, and the transaction continues in your app.
-(void)onPWInAppPurchaseHelperCallPromotedPurchase:(NSString* _Nullable)identifier;
@end
```

#### Failed restoring completed transactions

```objective-c
@protocol PWPurchaseDelegate <NSObject>
// An error occurred while restoring transactions
-(void)onPWInAppPurchaseHelperRestoreCompletedTransactionsFailed:(NSError * _Nullable)error;
@end
```

<Aside type="note">
If your needs are not covered with the methods specified in this guide, please reach out to our [Customer Support team](https://help.pushwoosh.com/hc/en-us/requests/new?utm\_content=pwwebsite\&utm\_term=footer\&utm\_campaign=support), and we’ll be happy to provide you with further guidance. 
</Aside>