Permalink
Browse files

Start wrapping checkout SDK to work with Play

  • Loading branch information...
1 parent 0990c54 commit 6c632319d86f2ac4654e29f4b1b14233a51d4672 @jagregory committed Nov 24, 2011
View
@@ -0,0 +1,2 @@
+tmp/
+*.pyc
@@ -0,0 +1,52 @@
+package models;
+
+import com.google.checkout.sdk.commands.ApiContext;
+import com.google.checkout.sdk.commands.Environment;
+import play.Play;
+
+public final class GoogleCheckoutApiFactory {
+ public static ApiContext build() throws GoogleCheckoutInitializationException {
+ Environment environment = isSandbox() ? Environment.SANDBOX : Environment.PRODUCTION;
+ String merchantId = getMerchantId();
+ String merchantKey = getMerchantKey();
+ String currency = getCurrency();
+
+ return new ApiContext(environment, merchantId, merchantKey, currency);
+ }
+
+ static String getMerchantId() throws GoogleCheckoutInitializationException {
+ Object merchantId = Play.configuration.get("googlecheckout.merchantid");
+
+ if (merchantId == null) {
+ throw new GoogleCheckoutInitializationException("Unable to read MerchantId from application.conf");
+ }
+
+ return merchantId.toString();
+ }
+
+ static String getMerchantKey() throws GoogleCheckoutInitializationException {
+ Object merchantKey = Play.configuration.get("googlecheckout.merchantkey");
+
+ if (merchantKey == null) {
+ throw new GoogleCheckoutInitializationException("Unable to read MerchantKey from application.conf");
+ }
+
+ return merchantKey.toString();
+ }
+
+ static String getCurrency() {
+ Object currency = Play.configuration.get("googlecheckout.currency");
+
+ if (currency == null) {
+ return "USD";
+ }
+
+ return currency.toString();
+ }
+
+ static boolean isSandbox() {
+ Object isSandbox = Play.configuration.get("googlecheckout.sandbox");
+
+ return isSandbox == null || isSandbox.equals(true);
+ }
+}
@@ -0,0 +1,10 @@
+package models;
+
+import com.google.checkout.sdk.commands.ApiContext;
+import com.google.checkout.sdk.commands.CartPoster;
+
+public final class GoogleCheckoutCartFactory {
+ public static CartPoster.CheckoutShoppingCartBuilder build(ApiContext api) {
+ return api.cartPoster().makeCart();
+ }
+}
@@ -0,0 +1,7 @@
+package models;
+
+public class GoogleCheckoutInitializationException extends Exception {
+ public GoogleCheckoutInitializationException(String message) {
+ super(message);
+ }
+}
@@ -0,0 +1,16 @@
+package models;
+
+import play.db.jpa.Model;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="GoogleCheckout_Notifications")
+public class GoogleCheckoutNotification extends Model {
+ public String SerialNumber;
+
+ public static boolean existsForSerialNumber(String serialNumber) {
+ return find("bySerialNumber", serialNumber).first() != null;
+ }
+}
Oops, something went wrong.

0 comments on commit 6c63231

Please sign in to comment.