Payload.checkout(new pl.Payment(10.12){{
set("processing_id", "acct_3bfCMwa8OwUbYOvUQKTGi");
}}, new CardReader.TransactionCallback(){
public void processing(pl.Payment pymt) { /* handle event */ }
public void processed(pl.Payment pymt) { /* handle event */ }
public void declined(pl.Payment pymt) { /* handle event */ }
public void timeout(pl.Payment pymt) { /* handle event */ }
});
import UIKit
import PayloadAPI
import PayloadCardReader
class PaymentController: UIViewController, PayloadPaymentDelegate {
var reader:Payload.CardReader!;
override func viewDidLoad() {
super.viewDidLoad()
do {
try Payload.Checkout(Payload.Payment(
amount: 10,
processing_id: "acct_3bfCMwa8OwUbYOvUQKTGi"
), delegate: self)
} catch let error as Payload.Errors.TransactionAlreadyStarted {
print(error.message)
}
}
func processing(_ payment:Payload.Payment) { /* handle event */ }
func processed(_ payment:Payload.Payment) { /* handle event */ }
func declined(_ payment:Payload.Payment) { /* handle event */ }
func timeout(_ payment:Payload.Payment) { /* handle event */ }
func error(_ payment:Payload.Payment,_ error:Payload.PayloadError) { /* handle event */ }
}
#import <UIKit/UIKit.h>
#import <Payload/Payload-Swift.h>
@interface PaymentController : UIViewController<PayloadPaymentDelegate>
@end
@interface PaymentController ()
@property CardReader *reader;
@end
@implementation PaymentController
- (void)viewDidLoad {
[super viewDidLoad];
NSError *error = nil;
[Payload Checkout:[[Payment alloc] init:@{
@"amount": @10,
@"processing_id": @"acct_3bfCMwa8OwUbYOvUQKTGi",
}] delegate: self error: &error];
if(error) {
[self console:[NSString stringWithFormat:@"Error finding Name1: %@", error]];
}
}
- (void)processed:(Payment * _Nonnull)payment { /* handle event */ }
- (void)processing:(Payment * _Nonnull)payment { /* handle event */ }
- (void)declined:(Payment * _Nonnull)payment { /* handle event */ }
- (void)timeout:(Payment * _Nonnull)payment { /* handle event */ }
- (void)error:(Payment * _Nonnull)payment :(PayloadError * _Nonnull)error { /* handle event */ }
@end
To initiate a payment request, you must call Checkout
with a Payload Payment
object. The minimum required fields for the Payment
object are amount
and processing_id
.
Once a payment request is submitted to Checkout
, you can track the progress of a transaction
by monitoring the payment events described below.
The processing
event is triggered once (1) the card information
has been received by the connected card reader or (2) the information has been
keyed in and the payment request has now been submitted
to Payload for processing.
The processed
event is triggered if the requested payment was approved and successfully processed.
The declined
event is triggered if a payment attempt is unsuccessful. You can
inspect the declined reason by reviewing the status_response_code
and
status_response_message
attributes.
Note: If "Raise Declined Error" is enabled on an API Key, an error event will be triggered if a payment is declined
The timeout
event is triggered if Checkout
is called but the
card reader device does not receive the card details and the request
expires.
The error
event is triggered if an error occurs while attempting to
process the payment request.
Error | Description |
---|---|
UnknownRequestError |
An unknown network error occurred |
LostConnectivity |
Connectivity was lost and offline payments is disabled |
RequestError |
A request error occurred. Inspect error_type , error_description , and details for information. |
if ( reader.isTransactionStarted() && !reader.isTransactionProcessing() ) {
reader.cancelTransaction();
}
if reader.isTransactionStarted() && !reader.isTransactionProcessing() {
try! reader.cancelTransaction();
}
if ([reader isTransactionStarted] && ![reader isTransactionProcessing]) {
[reader cancelTransaction];
}
You can check the status of a transaction with isTransactionStarted
and isTransactionProcessing
.
If a transaction has started but hasn't started processing you can cancel the transaction request on the
card reader with cancelTransaction
.
if ( reader.isTransactionProcessing() ) {
reader.cancelTransaction(true);
}
if reader.isTransactionProcessing() {
try! reader.cancelTransaction(force: true);
}
if ([reader isTransactionProcessing]) {
[reader cancelTransaction: force: true];
}
If a transaction has begun processing you can still forcibly cancel a transaction by passing force=true
to the
cancelTransaction
function.
You can control the desired method of card capture when calling
Checkout
by specifying the source
attribute on the
Payment
object.
Payload.checkout(new pl.Payment(10.12){{
set("source", "emv");
set("processing_id", "acct_3bfCMwa8OwUbYOvUQKTGi");
}}, callback);
Payload.Checkout(Payload.Payment(
amount: 10,
source: "emv",
processing_id: "acct_3bfCMwa8OwUbYOvUQKTGi"
), delegate: self )
NSError *error = nil;
[Payload Checkout:[[Payment alloc] init:@{
@"amount": @10,
@"source": @"emv",
@"processing_id": @"acct_3bfCMwa8OwUbYOvUQKTGi",
}] delegate: self error: &error];
Payload.checkout(new pl.Payment(10.12){{
set("source", "emv_quickchip");
set("processing_id", "acct_3bfCMwa8OwUbYOvUQKTGi");
}}, callback);
Payload.Checkout(Payload.Payment(
amount: 10,
source: "emv_quickchip",
processing_id: "acct_3bfCMwa8OwUbYOvUQKTGi"
), delegate: self )
NSError *error = nil;
[Payload Checkout:[[Payment alloc] init:@{
@"amount": @10,
@"source": @"emv_quickchip",
@"processing_id": @"acct_3bfCMwa8OwUbYOvUQKTGi",
}] delegate: self error: &error];
Payload.checkout(new pl.Payment(10.12){{
set("source", "swipe");
set("processing_id", "acct_3bfCMwa8OwUbYOvUQKTGi");
}}, callback);
Payload.Checkout(Payload.Payment(
amount: 10,
source: "swipe",
processing_id: "acct_3bfCMwa8OwUbYOvUQKTGi"
), delegate: self )
NSError *error = nil;
[Payload Checkout:[[Payment alloc] init:@{
@"amount": @10,
@"source": @"swipe",
@"processing_id": @"acct_3bfCMwa8OwUbYOvUQKTGi",
}] delegate: self error: &error];
Payload.checkout(new pl.Payment(10.12){{
set("source", "nfc");
set("processing_id", "acct_3bfCMwa8OwUbYOvUQKTGi");
}}, callback);
Payload.Checkout(Payload.Payment(
amount: 10,
source: "nfc",
processing_id: "acct_3bfCMwa8OwUbYOvUQKTGi"
), delegate: self )
NSError *error = nil;
[Payload Checkout:[[Payment alloc] init:@{
@"amount": @10,
@"source": @"nfc",
@"processing_id": @"acct_3bfCMwa8OwUbYOvUQKTGi",
}] delegate: self error: &error];
Payload.checkout(new pl.Payment(10.12){{
set("source", "keyed");
set("processing_id", "acct_3bfCMwa8OwUbYOvUQKTGi");
}}, callback);
Payload.Checkout(Payload.Payment(
amount: 10,
source: "keyed",
processing_id: "acct_3bfCMwa8OwUbYOvUQKTGi"
), delegate: self )
NSError *error = nil;
[Payload Checkout:[[Payment alloc] init:@{
@"amount": @10,
@"source": @"keyed",
@"processing_id": @"acct_3bfCMwa8OwUbYOvUQKTGi",
}] delegate: self error: &error];
Manual Keyed View Dismissal
checkout.dismiss()
By default, the keyed checkout interface will close once a transaction is complete but you can override this default behavior and control when you want to close the keyed view.
Keyed View Themes
PayloadFormLabel.appearance().textColor = UIColor.blueColor();
PayloadCard.appearance().backgroundColor = UIColor.cyanColor();
PayloadCardContainer.appearance().backgroundColor = UIColor.lightGrayColor();
PayloadPayBtn.appearance().backgroundColor = UIColor.blueColor();
Class Name | Description |
---|---|
PayloadFormLabel |
The labels above the inputs |
PayloadTitle |
The title text on the Checkout view |
PayloadCardContainer |
The card display container |
PayloadCard |
The card display example |
PayloadCardLabel |
The labels above the inputted text in the card display |
PayloadCardTextField |
The inputted text in the card display |
PayoadPayBtn |
The pay button at the bottom of the page |