CoFeePayment class
The main entry point for the CoFee Payment SDK.
This class provides a simple interface for initiating payments using the CoFee payment system. It handles the entire payment flow, from fetching payment details to processing the payment and notifying when the payment is complete.
The SDK supports both sandbox (testing) and production environments through the PaymentEnvironment parameter. Use PaymentEnvironment.sandbox during development and testing, and PaymentEnvironment.production for live transactions.
Example usage:
final coFeePayment = CoFeePayment(
clientId: 'your-client-id',
paymentEnvironment: PaymentEnvironment.sandbox,
);
coFeePayment.pay(
'order-123',
onFinish: () {
print('Payment completed');
},
onError: (error) {
if (error.errorType == PaymentErrorType.network) {
print('Network error: ${error.message}');
}
},
);
IMPORTANT: The completion callback only indicates that the payment flow has finished in the browser. It does NOT guarantee that the payment was successful. The application MUST verify the payment status with the server after receiving the callback.
Constructors
- CoFeePayment.new({required String clientId, required PaymentEnvironment paymentEnvironment})
-
Creates a CoFeePayment instance with the specified
clientId
andpaymentEnvironment
.
Properties
- clientId → String
-
The client ID for authentication with the CoFee payment API.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- paymentEnvironment → PaymentEnvironment
-
The environment in which payments will be processed.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pay(
String orderId, {required PaymentCompletionCallback onFinish, required PaymentErrorCallback onError}) → Future< void> -
Initiates the payment flow for the specified
orderId
. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited