These are the steps to upgrade from SDK v1 to v2
- In your
build.gradle
file, update the version number of Affirm SDK to the latest version (2.x.x) - Sync gradle
-
Initialize the SDK
publicKey
andenvironment
are required.setMerchantName
is an optional step.- Added optional
LogLevel
Before:
Affirm.builder() .setEnvironment(Affirm.Environment.SANDBOX) .setMerchantPublicKey("public key") .build();
Now:
Affirm.initialize(new Affirm.Configuration.Builder("public key", Affirm.Environment.SANDBOX) .setMerchantName(null) .setLogLevel(Affirm.LOG_LEVEL_DEBUG) .build() );
-
Promotional Messaging
- Added
AffirmPromotionButton
class, you can declare it in anxml
file or create it directly vianew
. You can then set thepromoId
(optional),pageType
(optional) andamount
values with theconfigureWithAmount
method.
Before
CancellableRequest aslowasPromo = affirm.writePromoToTextView(promo, null, 1100, AffirmDisplayTypeLogo, AffirmColorTypeBlue, true, new PromoCallback() { @Override public void onPromoWritten(TextView textView) { aslowasPromo = null; } @Override public void onFailure(TextView textView, final Throwable throwable) { runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, "As low as label : " + throwable.getMessage(), Toast.LENGTH_LONG).shsysow(); aslowasPromo = null; } }); } }); @Override protected void onPause() { super.onPause(); if (aslowasPromo != null) { aslowasPromo.cancelRequest(); } }
Now
AffirmPromotionButton affirmPromotionButton = findViewById(R.id.promo); Affirm.configureWithAmount(affirmPromotionButton, null, PromoPageType.PRODUCT, 1100, true);
- Added optional
PrequalCallbacks
, you can catch prequalfailure
through this callback.
@Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { if (Affirm.handlePrequalData(this, requestCode, resultCode, data)) { return; } super.onActivityResult(requestCode, resultCode, data); } @Override public void onAffirmPrequalError(String message) { Toast.makeText(this, "Prequal Error: " + message, Toast.LENGTH_LONG).show(); }
- Added
-
Checkout
- Both checkout and VCN checkout now use the unified method
startCheckout
, differentiated by the boolean parameteruseVCN
.
Take vcn checkout as an example, checkout is also similar
Before
final Checkout checkout = Checkout.builder() .setItems(items) .setBilling(shipping) .setShipping(shipping) .setShippingAmount(0f) .setTaxAmount(100f) .setTotal(1100f) .build(); affirm.launchVcnCheckout(this, checkout); @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (affirm.onVcnCheckoutActivityResult(this, requestCode, resultCode, data)) { return; } super.onActivityResult(requestCode, resultCode, data); }
Now
final Checkout checkout = Checkout.builder() .setItems(items) .setBilling(shipping) .setShipping(shipping) .setShippingAmount(0f) .setTaxAmount(100f) .setTotal(1100f) .build(); Affirm.startCheckout(this, checkout, true); @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { if (Affirm.handleVcnCheckoutData(this, requestCode, resultCode, data)) { return; } super.onActivityResult(requestCode, resultCode, data); }
- Both checkout and VCN checkout now use the unified method
-
Track Order Confirmed
final AffirmTrack affirmTrack = AffirmTrack.builder() .setAffirmTrackOrder(affirmTrackOrder) .setAffirmTrackProducts(affirmTrackProducts) .build(); Affirm.trackOrderConfirmed(MainActivity.this, trackModel());
Rebuild you project, if there is no compile error and after testing everything is working as you expected. Congratulations! you can ship it now :)