adyen_jpiqueras 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.travis.yml +30 -0
  4. data/CHANGELOG.md +128 -0
  5. data/CONTRIBUTING.md +85 -0
  6. data/Gemfile +11 -0
  7. data/LICENSE +21 -0
  8. data/README.md +31 -0
  9. data/Rakefile +54 -0
  10. data/adyen_jpiqueras.gemspec +44 -0
  11. data/config.ru +5 -0
  12. data/lib/adyen.rb +16 -0
  13. data/lib/adyen/api.rb +424 -0
  14. data/lib/adyen/api/cacert.pem +3894 -0
  15. data/lib/adyen/api/payment_service.rb +374 -0
  16. data/lib/adyen/api/recurring_service.rb +188 -0
  17. data/lib/adyen/api/response.rb +61 -0
  18. data/lib/adyen/api/simple_soap_client.rb +134 -0
  19. data/lib/adyen/api/templates/payment_service.rb +159 -0
  20. data/lib/adyen/api/templates/recurring_service.rb +71 -0
  21. data/lib/adyen/api/test_helpers.rb +133 -0
  22. data/lib/adyen/api/xml_querier.rb +137 -0
  23. data/lib/adyen/base.rb +17 -0
  24. data/lib/adyen/configuration.rb +179 -0
  25. data/lib/adyen/form.rb +419 -0
  26. data/lib/adyen/hpp.rb +27 -0
  27. data/lib/adyen/hpp/request.rb +192 -0
  28. data/lib/adyen/hpp/response.rb +52 -0
  29. data/lib/adyen/hpp/signature.rb +34 -0
  30. data/lib/adyen/matchers.rb +92 -0
  31. data/lib/adyen/notification_generator.rb +30 -0
  32. data/lib/adyen/railtie.rb +13 -0
  33. data/lib/adyen/rest.rb +67 -0
  34. data/lib/adyen/rest/authorise_payment.rb +234 -0
  35. data/lib/adyen/rest/authorise_recurring_payment.rb +46 -0
  36. data/lib/adyen/rest/client.rb +127 -0
  37. data/lib/adyen/rest/errors.rb +33 -0
  38. data/lib/adyen/rest/modify_payment.rb +89 -0
  39. data/lib/adyen/rest/payout.rb +89 -0
  40. data/lib/adyen/rest/request.rb +104 -0
  41. data/lib/adyen/rest/response.rb +80 -0
  42. data/lib/adyen/rest/signature.rb +27 -0
  43. data/lib/adyen/signature.rb +76 -0
  44. data/lib/adyen/templates/notification_migration.rb +29 -0
  45. data/lib/adyen/templates/notification_model.rb +69 -0
  46. data/lib/adyen/util.rb +147 -0
  47. data/lib/adyen/version.rb +5 -0
  48. data/spec/api/api_spec.rb +231 -0
  49. data/spec/api/payment_service_spec.rb +505 -0
  50. data/spec/api/recurring_service_spec.rb +236 -0
  51. data/spec/api/response_spec.rb +59 -0
  52. data/spec/api/simple_soap_client_spec.rb +133 -0
  53. data/spec/api/spec_helper.rb +463 -0
  54. data/spec/api/test_helpers_spec.rb +84 -0
  55. data/spec/functional/api_spec.rb +117 -0
  56. data/spec/functional/initializer.rb.ci +3 -0
  57. data/spec/functional/initializer.rb.sample +3 -0
  58. data/spec/spec_helper.rb +8 -0
  59. data/test/form_test.rb +303 -0
  60. data/test/functional/payment_authorisation_api_test.rb +107 -0
  61. data/test/functional/payment_modification_api_test.rb +58 -0
  62. data/test/functional/payout_api_test.rb +93 -0
  63. data/test/helpers/capybara.rb +12 -0
  64. data/test/helpers/configure_adyen.rb +6 -0
  65. data/test/helpers/example_server.rb +136 -0
  66. data/test/helpers/public/adyen.encrypt.js +679 -0
  67. data/test/helpers/public/adyen.encrypt.min.js +14 -0
  68. data/test/helpers/test_cards.rb +20 -0
  69. data/test/helpers/views/authorized.erb +7 -0
  70. data/test/helpers/views/hpp.erb +20 -0
  71. data/test/helpers/views/index.erb +6 -0
  72. data/test/helpers/views/pay.erb +36 -0
  73. data/test/helpers/views/redirect_shopper.erb +18 -0
  74. data/test/hpp/signature_test.rb +37 -0
  75. data/test/hpp_test.rb +250 -0
  76. data/test/integration/hpp_integration_test.rb +52 -0
  77. data/test/integration/payment_using_3d_secure_integration_test.rb +41 -0
  78. data/test/integration/payment_with_client_side_encryption_integration_test.rb +26 -0
  79. data/test/rest/signature_test.rb +36 -0
  80. data/test/rest_list_recurring_details_response_test.rb +22 -0
  81. data/test/rest_request_test.rb +43 -0
  82. data/test/rest_response_test.rb +19 -0
  83. data/test/signature_test.rb +76 -0
  84. data/test/test_helper.rb +45 -0
  85. data/test/util_test.rb +78 -0
  86. data/yard_extensions.rb +16 -0
  87. metadata +308 -0
@@ -0,0 +1,14 @@
1
+ /*
2
+ *
3
+ * Client Encryption of Forms.
4
+ *
5
+ * Includes:
6
+ * * RSA and ECC in JavaScript | http://www-cs-students.stanford.edu/~tjw/jsbn/
7
+ * * Stanford Javascript Crypto Library | http://crypto.stanford.edu/sjcl/
8
+ * * JSON in JavaScript | http://www.JSON.org/
9
+ *
10
+ * Version: 0_1_7
11
+ * Author: ADYEN (c) 2014
12
+ */
13
+ (function(){(function(){try{var b=[new Uint8Array(1),new Uint32Array(1),new Int32Array(1)];return}catch(g){}function f(e,a){return this.slice(e,a)}function c(j,e){if(arguments.length<2){e=0}for(var a=0,h=j.length;a<h;++a,++e){this[e]=j[a]&255}}function d(e){var a;if(typeof e==="number"){a=new Array(e);for(var h=0;h<e;++h){a[h]=0}}else{a=e.slice(0)}a.subarray=f;a.buffer=a;a.byteLength=a.length;a.set=c;if(typeof e==="object"&&e.buffer){a.buffer=e.buffer}return a}try{window.Uint8Array=d}catch(g){}try{window.Uint32Array=d}catch(g){}try{window.Int32Array=d}catch(g){}})();(function(){if("response" in XMLHttpRequest.prototype||"mozResponseArrayBuffer" in XMLHttpRequest.prototype||"mozResponse" in XMLHttpRequest.prototype||"responseArrayBuffer" in XMLHttpRequest.prototype){return}try{Object.defineProperty(XMLHttpRequest.prototype,"response",{get:function(){return new Uint8Array(new VBArray(this.responseBody).toArray())}})}catch(a){}})();(function(){if("btoa" in window){return}var a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";window.btoa=function(g){var e="";var f,d;for(f=0,d=g.length;f<d;f+=3){var k=g.charCodeAt(f)&255;var j=g.charCodeAt(f+1)&255;var h=g.charCodeAt(f+2)&255;var c=k>>2,b=((k&3)<<4)|(j>>4);var m=f+1<d?((j&15)<<2)|(h>>6):64;var l=f+2<d?(h&63):64;e+=a.charAt(c)+a.charAt(b)+a.charAt(m)+a.charAt(l)}return e}})();if(typeof JSON!=="object"){JSON={}}(function(){function f(n){return n<10?"0"+n:n}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==="string"?c:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+string+'"'}function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==="object"&&typeof value.toJSON==="function"){value=value.toJSON(key)}if(typeof rep==="function"){value=rep.call(holder,key,value)}switch(typeof value){case"string":return quote(value);case"number":return isFinite(value)?String(value):"null";case"boolean":case"null":return String(value);case"object":if(!value){return"null"}gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==="[object Array]"){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||"null"}v=partial.length===0?"[]":gap?"[\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"]":"["+partial.join(",")+"]";gap=mind;return v}if(rep&&typeof rep==="object"){length=rep.length;for(i=0;i<length;i+=1){if(typeof rep[i]==="string"){k=rep[i];v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}else{for(k in value){if(Object.prototype.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}v=partial.length===0?"{}":gap?"{\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"}":"{"+partial.join(",")+"}";gap=mind;return v}}if(typeof JSON.stringify!=="function"){JSON.stringify=function(value,replacer,space){var i;gap="";indent="";if(typeof space==="number"){for(i=0;i<space;i+=1){indent+=" "}}else{if(typeof space==="string"){indent=space}}rep=replacer;if(replacer&&typeof replacer!=="function"&&(typeof replacer!=="object"||typeof replacer.length!=="number")){throw new Error("JSON.stringify")}return str("",{"":value})}}if(typeof JSON.parse!=="function"){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==="object"){for(k in value){if(Object.prototype.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v}else{delete value[k]}}}}return reviver.call(holder,key,value)}text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){j=eval("("+text+")");return typeof reviver==="function"?walk({"":j},""):j}throw new SyntaxError("JSON.parse")}}}());var b64map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var b64padchar="=";function hex2b64(d){var b;var e;var a="";for(b=0;b+3<=d.length;b+=3){e=parseInt(d.substring(b,b+3),16);a+=b64map.charAt(e>>6)+b64map.charAt(e&63)}if(b+1==d.length){e=parseInt(d.substring(b,b+1),16);a+=b64map.charAt(e<<2)}else{if(b+2==d.length){e=parseInt(d.substring(b,b+2),16);a+=b64map.charAt(e>>2)+b64map.charAt((e&3)<<4)}}while((a.length&3)>0){a+=b64padchar}return a}function b64tohex(e){var c="";var d;var a=0;var b;for(d=0;d<e.length;++d){if(e.charAt(d)==b64padchar){break}v=b64map.indexOf(e.charAt(d));if(v<0){continue}if(a==0){c+=int2char(v>>2);b=v&3;a=1}else{if(a==1){c+=int2char((b<<2)|(v>>4));b=v&15;a=2}else{if(a==2){c+=int2char(b);c+=int2char(v>>2);b=v&3;a=3}else{c+=int2char((b<<2)|(v>>4));c+=int2char(v&15);a=0}}}}if(a==1){c+=int2char(b<<2)}return c}function b64toBA(e){var d=b64tohex(e);var c;var b=new Array();for(c=0;2*c<d.length;++c){b[c]=parseInt(d.substring(2*c,2*c+2),16)}return b}var dbits;var canary=244837814094590;var j_lm=((canary&16777215)==15715070);function BigInteger(e,d,f){if(e!=null){if("number"==typeof e){this.fromNumber(e,d,f)}else{if(d==null&&"string"!=typeof e){this.fromString(e,256)}else{this.fromString(e,d)}}}}function nbi(){return new BigInteger(null)}function am1(f,a,b,e,h,g){while(--g>=0){var d=a*this[f++]+b[e]+h;h=Math.floor(d/67108864);b[e++]=d&67108863}return h}function am2(f,q,r,e,o,a){var k=q&32767,p=q>>15;while(--a>=0){var d=this[f]&32767;var g=this[f++]>>15;var b=p*d+g*k;d=k*d+((b&32767)<<15)+r[e]+(o&1073741823);o=(d>>>30)+(b>>>15)+p*g+(o>>>30);r[e++]=d&1073741823}return o}function am3(f,q,r,e,o,a){var k=q&16383,p=q>>14;while(--a>=0){var d=this[f]&16383;var g=this[f++]>>14;var b=p*d+g*k;d=k*d+((b&16383)<<14)+r[e]+o;o=(d>>28)+(b>>14)+p*g;r[e++]=d&268435455}return o}if(j_lm&&(navigator.appName=="Microsoft Internet Explorer")){BigInteger.prototype.am=am2;dbits=30}else{if(j_lm&&(navigator.appName!="Netscape")){BigInteger.prototype.am=am1;dbits=26}else{BigInteger.prototype.am=am3;dbits=28}}BigInteger.prototype.DB=dbits;BigInteger.prototype.DM=((1<<dbits)-1);BigInteger.prototype.DV=(1<<dbits);var BI_FP=52;BigInteger.prototype.FV=Math.pow(2,BI_FP);BigInteger.prototype.F1=BI_FP-dbits;BigInteger.prototype.F2=2*dbits-BI_FP;var BI_RM="0123456789abcdefghijklmnopqrstuvwxyz";var BI_RC=new Array();var rr,vv;rr="0".charCodeAt(0);for(vv=0;vv<=9;++vv){BI_RC[rr++]=vv}rr="a".charCodeAt(0);for(vv=10;vv<36;++vv){BI_RC[rr++]=vv}rr="A".charCodeAt(0);for(vv=10;vv<36;++vv){BI_RC[rr++]=vv}function int2char(a){return BI_RM.charAt(a)}function intAt(b,a){var d=BI_RC[b.charCodeAt(a)];return(d==null)?-1:d}function bnpCopyTo(b){for(var a=this.t-1;a>=0;--a){b[a]=this[a]}b.t=this.t;b.s=this.s}function bnpFromInt(a){this.t=1;this.s=(a<0)?-1:0;if(a>0){this[0]=a}else{if(a<-1){this[0]=a+this.DV}else{this.t=0}}}function nbv(a){var b=nbi();b.fromInt(a);return b}function bnpFromString(h,c){var e;if(c==16){e=4}else{if(c==8){e=3}else{if(c==256){e=8}else{if(c==2){e=1}else{if(c==32){e=5}else{if(c==4){e=2}else{this.fromRadix(h,c);return}}}}}}this.t=0;this.s=0;var g=h.length,d=false,f=0;while(--g>=0){var a=(e==8)?h[g]&255:intAt(h,g);if(a<0){if(h.charAt(g)=="-"){d=true}continue}d=false;if(f==0){this[this.t++]=a}else{if(f+e>this.DB){this[this.t-1]|=(a&((1<<(this.DB-f))-1))<<f;this[this.t++]=(a>>(this.DB-f))}else{this[this.t-1]|=a<<f}}f+=e;if(f>=this.DB){f-=this.DB}}if(e==8&&(h[0]&128)!=0){this.s=-1;if(f>0){this[this.t-1]|=((1<<(this.DB-f))-1)<<f}}this.clamp();if(d){BigInteger.ZERO.subTo(this,this)}}function bnpClamp(){var a=this.s&this.DM;while(this.t>0&&this[this.t-1]==a){--this.t}}function bnToString(c){if(this.s<0){return"-"+this.negate().toString(c)}var e;if(c==16){e=4}else{if(c==8){e=3}else{if(c==2){e=1}else{if(c==32){e=5}else{if(c==4){e=2}else{return this.toRadix(c)}}}}}var g=(1<<e)-1,l,a=false,h="",f=this.t;var j=this.DB-(f*this.DB)%e;if(f-->0){if(j<this.DB&&(l=this[f]>>j)>0){a=true;h=int2char(l)}while(f>=0){if(j<e){l=(this[f]&((1<<j)-1))<<(e-j);l|=this[--f]>>(j+=this.DB-e)}else{l=(this[f]>>(j-=e))&g;if(j<=0){j+=this.DB;--f}}if(l>0){a=true}if(a){h+=int2char(l)}}}return a?h:"0"}function bnNegate(){var a=nbi();BigInteger.ZERO.subTo(this,a);return a}function bnAbs(){return(this.s<0)?this.negate():this}function bnCompareTo(b){var d=this.s-b.s;if(d!=0){return d}var c=this.t;d=c-b.t;if(d!=0){return(this.s<0)?-d:d}while(--c>=0){if((d=this[c]-b[c])!=0){return d}}return 0}function nbits(a){var c=1,b;if((b=a>>>16)!=0){a=b;c+=16}if((b=a>>8)!=0){a=b;c+=8}if((b=a>>4)!=0){a=b;c+=4}if((b=a>>2)!=0){a=b;c+=2}if((b=a>>1)!=0){a=b;c+=1}return c}function bnBitLength(){if(this.t<=0){return 0}return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM))}function bnpDLShiftTo(c,b){var a;for(a=this.t-1;a>=0;--a){b[a+c]=this[a]}for(a=c-1;a>=0;--a){b[a]=0}b.t=this.t+c;b.s=this.s}function bnpDRShiftTo(c,b){for(var a=c;a<this.t;++a){b[a-c]=this[a]}b.t=Math.max(this.t-c,0);b.s=this.s}function bnpLShiftTo(j,e){var b=j%this.DB;var a=this.DB-b;var g=(1<<a)-1;var f=Math.floor(j/this.DB),h=(this.s<<b)&this.DM,d;for(d=this.t-1;d>=0;--d){e[d+f+1]=(this[d]>>a)|h;h=(this[d]&g)<<b}for(d=f-1;d>=0;--d){e[d]=0}e[f]=h;e.t=this.t+f+1;e.s=this.s;e.clamp()}function bnpRShiftTo(g,d){d.s=this.s;var e=Math.floor(g/this.DB);if(e>=this.t){d.t=0;return}var b=g%this.DB;var a=this.DB-b;var f=(1<<b)-1;d[0]=this[e]>>b;for(var c=e+1;c<this.t;++c){d[c-e-1]|=(this[c]&f)<<a;d[c-e]=this[c]>>b}if(b>0){d[this.t-e-1]|=(this.s&f)<<a}d.t=this.t-e;d.clamp()}function bnpSubTo(d,f){var e=0,g=0,b=Math.min(d.t,this.t);while(e<b){g+=this[e]-d[e];f[e++]=g&this.DM;g>>=this.DB}if(d.t<this.t){g-=d.s;while(e<this.t){g+=this[e];f[e++]=g&this.DM;g>>=this.DB}g+=this.s}else{g+=this.s;while(e<d.t){g-=d[e];f[e++]=g&this.DM;g>>=this.DB}g-=d.s}f.s=(g<0)?-1:0;if(g<-1){f[e++]=this.DV+g}else{if(g>0){f[e++]=g}}f.t=e;f.clamp()}function bnpMultiplyTo(c,e){var b=this.abs(),f=c.abs();var d=b.t;e.t=d+f.t;while(--d>=0){e[d]=0}for(d=0;d<f.t;++d){e[d+b.t]=b.am(0,f[d],e,d,0,b.t)}e.s=0;e.clamp();if(this.s!=c.s){BigInteger.ZERO.subTo(e,e)}}function bnpSquareTo(d){var a=this.abs();var b=d.t=2*a.t;while(--b>=0){d[b]=0}for(b=0;b<a.t-1;++b){var e=a.am(b,a[b],d,2*b,0,1);if((d[b+a.t]+=a.am(b+1,2*a[b],d,2*b+1,e,a.t-b-1))>=a.DV){d[b+a.t]-=a.DV;d[b+a.t+1]=1}}if(d.t>0){d[d.t-1]+=a.am(b,a[b],d,2*b,0,1)}d.s=0;d.clamp()}function bnpDivRemTo(n,h,g){var w=n.abs();if(w.t<=0){return}var k=this.abs();if(k.t<w.t){if(h!=null){h.fromInt(0)}if(g!=null){this.copyTo(g)}return}if(g==null){g=nbi()}var d=nbi(),a=this.s,l=n.s;var v=this.DB-nbits(w[w.t-1]);if(v>0){w.lShiftTo(v,d);k.lShiftTo(v,g)}else{w.copyTo(d);k.copyTo(g)}var p=d.t;var b=d[p-1];if(b==0){return}var o=b*(1<<this.F1)+((p>1)?d[p-2]>>this.F2:0);var A=this.FV/o,z=(1<<this.F1)/o,x=1<<this.F2;var u=g.t,s=u-p,f=(h==null)?nbi():h;d.dlShiftTo(s,f);if(g.compareTo(f)>=0){g[g.t++]=1;g.subTo(f,g)}BigInteger.ONE.dlShiftTo(p,f);f.subTo(d,d);while(d.t<p){d[d.t++]=0}while(--s>=0){var c=(g[--u]==b)?this.DM:Math.floor(g[u]*A+(g[u-1]+x)*z);if((g[u]+=d.am(0,c,g,s,0,p))<c){d.dlShiftTo(s,f);g.subTo(f,g);while(g[u]<--c){g.subTo(f,g)}}}if(h!=null){g.drShiftTo(p,h);if(a!=l){BigInteger.ZERO.subTo(h,h)}}g.t=p;g.clamp();if(v>0){g.rShiftTo(v,g)}if(a<0){BigInteger.ZERO.subTo(g,g)}}function bnMod(b){var c=nbi();this.abs().divRemTo(b,null,c);if(this.s<0&&c.compareTo(BigInteger.ZERO)>0){b.subTo(c,c)}return c}function Classic(a){this.m=a}function cConvert(a){if(a.s<0||a.compareTo(this.m)>=0){return a.mod(this.m)}else{return a}}function cRevert(a){return a}function cReduce(a){a.divRemTo(this.m,null,a)}function cMulTo(a,c,b){a.multiplyTo(c,b);this.reduce(b)}function cSqrTo(a,b){a.squareTo(b);this.reduce(b)}Classic.prototype.convert=cConvert;Classic.prototype.revert=cRevert;Classic.prototype.reduce=cReduce;Classic.prototype.mulTo=cMulTo;Classic.prototype.sqrTo=cSqrTo;function bnpInvDigit(){if(this.t<1){return 0}var a=this[0];if((a&1)==0){return 0}var b=a&3;b=(b*(2-(a&15)*b))&15;b=(b*(2-(a&255)*b))&255;b=(b*(2-(((a&65535)*b)&65535)))&65535;b=(b*(2-a*b%this.DV))%this.DV;return(b>0)?this.DV-b:-b}function Montgomery(a){this.m=a;this.mp=a.invDigit();this.mpl=this.mp&32767;this.mph=this.mp>>15;this.um=(1<<(a.DB-15))-1;this.mt2=2*a.t}function montConvert(a){var b=nbi();a.abs().dlShiftTo(this.m.t,b);b.divRemTo(this.m,null,b);if(a.s<0&&b.compareTo(BigInteger.ZERO)>0){this.m.subTo(b,b)}return b}function montRevert(a){var b=nbi();a.copyTo(b);this.reduce(b);return b}function montReduce(a){while(a.t<=this.mt2){a[a.t++]=0}for(var c=0;c<this.m.t;++c){var b=a[c]&32767;var d=(b*this.mpl+(((b*this.mph+(a[c]>>15)*this.mpl)&this.um)<<15))&a.DM;b=c+this.m.t;a[b]+=this.m.am(0,d,a,c,0,this.m.t);while(a[b]>=a.DV){a[b]-=a.DV;a[++b]++}}a.clamp();a.drShiftTo(this.m.t,a);if(a.compareTo(this.m)>=0){a.subTo(this.m,a)}}function montSqrTo(a,b){a.squareTo(b);this.reduce(b)}function montMulTo(a,c,b){a.multiplyTo(c,b);this.reduce(b)}Montgomery.prototype.convert=montConvert;Montgomery.prototype.revert=montRevert;Montgomery.prototype.reduce=montReduce;Montgomery.prototype.mulTo=montMulTo;Montgomery.prototype.sqrTo=montSqrTo;function bnpIsEven(){return((this.t>0)?(this[0]&1):this.s)==0}function bnpExp(h,j){if(h>4294967295||h<1){return BigInteger.ONE}var f=nbi(),a=nbi(),d=j.convert(this),c=nbits(h)-1;d.copyTo(f);while(--c>=0){j.sqrTo(f,a);if((h&(1<<c))>0){j.mulTo(a,d,f)}else{var b=f;f=a;a=b}}return j.revert(f)}function bnModPowInt(b,a){var c;if(b<256||a.isEven()){c=new Classic(a)}else{c=new Montgomery(a)}return this.exp(b,c)}BigInteger.prototype.copyTo=bnpCopyTo;BigInteger.prototype.fromInt=bnpFromInt;BigInteger.prototype.fromString=bnpFromString;BigInteger.prototype.clamp=bnpClamp;BigInteger.prototype.dlShiftTo=bnpDLShiftTo;BigInteger.prototype.drShiftTo=bnpDRShiftTo;BigInteger.prototype.lShiftTo=bnpLShiftTo;BigInteger.prototype.rShiftTo=bnpRShiftTo;BigInteger.prototype.subTo=bnpSubTo;BigInteger.prototype.multiplyTo=bnpMultiplyTo;BigInteger.prototype.squareTo=bnpSquareTo;BigInteger.prototype.divRemTo=bnpDivRemTo;BigInteger.prototype.invDigit=bnpInvDigit;BigInteger.prototype.isEven=bnpIsEven;BigInteger.prototype.exp=bnpExp;BigInteger.prototype.toString=bnToString;BigInteger.prototype.negate=bnNegate;BigInteger.prototype.abs=bnAbs;BigInteger.prototype.compareTo=bnCompareTo;BigInteger.prototype.bitLength=bnBitLength;BigInteger.prototype.mod=bnMod;BigInteger.prototype.modPowInt=bnModPowInt;BigInteger.ZERO=nbv(0);BigInteger.ONE=nbv(1);function Arcfour(){this.i=0;this.j=0;this.S=new Array}function ARC4init(c){var a,d,b;for(a=0;a<256;++a){this.S[a]=a}d=0;for(a=0;a<256;++a){d=d+this.S[a]+c[a%c.length]&255;b=this.S[a];this.S[a]=this.S[d];this.S[d]=b}this.i=0;this.j=0}function ARC4next(){var a;this.i=this.i+1&255;this.j=this.j+this.S[this.i]&255;a=this.S[this.i];this.S[this.i]=this.S[this.j];this.S[this.j]=a;return this.S[a+this.S[this.i]&255]}function prng_newstate(){return new Arcfour}Arcfour.prototype.init=ARC4init;Arcfour.prototype.next=ARC4next;var rng_psize=256;var rng_state;var rng_pool;var rng_pptr;function rng_seed_int(a){rng_pool[rng_pptr++]^=a&255;rng_pool[rng_pptr++]^=(a>>8)&255;rng_pool[rng_pptr++]^=(a>>16)&255;rng_pool[rng_pptr++]^=(a>>24)&255;if(rng_pptr>=rng_psize){rng_pptr-=rng_psize}}function rng_seed_time(){rng_seed_int(new Date().getTime())}if(rng_pool==null){rng_pool=[];rng_pptr=0;var t;try{if(window.crypto&&window.crypto.getRandomValues){var ua=new Uint8Array(32);window.crypto.getRandomValues(ua);for(t=0;t<32;++t){rng_pool[rng_pptr++]=ua[t]}}else{if(window.msCrypto&&window.msCrypto.getRandomValues){var ua=new Uint8Array(32);window.msCrypto.getRandomValues(ua);for(t=0;t<32;++t){rng_pool[rng_pptr++]=ua[t]}}else{if(window.crypto&&window.crypto.random){var z=window.crypto.random(32);for(t=0;t<z.length;++t){rng_pool[rng_pptr++]=z.charCodeAt(t)&255}}}}}catch(e){}while(rng_pptr<rng_psize){t=Math.floor(65536*Math.random());rng_pool[rng_pptr++]=t>>>8;rng_pool[rng_pptr++]=t&255}rng_pptr=0;rng_seed_time()}function rng_get_byte(){if(rng_state==null){rng_seed_time();rng_state=prng_newstate();rng_state.init(rng_pool);for(rng_pptr=0;rng_pptr<rng_pool.length;++rng_pptr){rng_pool[rng_pptr]=0}rng_pptr=0}return rng_state.next()}function rng_get_bytes(b){var a;for(a=0;a<b.length;++a){b[a]=rng_get_byte()}}function SecureRandom(){}SecureRandom.prototype.nextBytes=rng_get_bytes;function parseBigInt(b,a){return new BigInteger(b,a)}function pkcs1pad2(c,g){if(g<c.length+11){alert("Message too long for RSA");return null}var f=new Array();var e=c.length-1;while(e>=0&&g>0){f[--g]=c[e--]}f[--g]=0;var d=new SecureRandom();var a=new Array();while(g>2){a[0]=0;while(a[0]==0){d.nextBytes(a)}f[--g]=a[0]}f[--g]=2;f[--g]=0;return new BigInteger(f)}function RSAKey(){this.n=null;this.e=0;this.d=null;this.p=null;this.q=null;this.dmp1=null;this.dmq1=null;this.coeff=null}function RSASetPublic(b,a){if(b!=null&&a!=null&&b.length>0&&a.length>0){this.n=parseBigInt(b,16);this.e=parseInt(a,16)}else{alert("Invalid RSA public key")}}function RSADoPublic(a){return a.modPowInt(this.e,this.n)}function RSAEncrypt(b){var a=pkcs1pad2(b,(this.n.bitLength()+7)>>3);if(a==null){return null}var e=this.doPublic(a);if(e==null){return null}var d=e.toString(16);if((d.length&1)==0){return d}else{return"0"+d}}function RSAEncryptB64(a){var b=this.encrypt(a);if(b){return hex2b64(b)}else{return null}}RSAKey.prototype.doPublic=RSADoPublic;RSAKey.prototype.setPublic=RSASetPublic;RSAKey.prototype.encrypt=RSAEncrypt;RSAKey.prototype.encrypt_b64=RSAEncryptB64;"use strict";function q(b){throw b}var r=void 0,t=!1;var sjcl={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(b){this.toString=function(){return"CORRUPT: "+this.message};this.message=b},invalid:function(b){this.toString=function(){return"INVALID: "+this.message};this.message=b},bug:function(b){this.toString=function(){return"BUG: "+this.message};this.message=b},notReady:function(b){this.toString=function(){return"NOT READY: "+this.message};this.message=b}}};"undefined"!==typeof module&&module.exports&&(module.exports=sjcl);sjcl.cipher.aes=function(j){this.i[0][0][0]||this.v();var i,p,o,n,l=this.i[0][4],m=this.i[1];i=j.length;var k=1;4!==i&&(6!==i&&8!==i)&&q(new sjcl.exception.invalid("invalid aes key size"));this.b=[o=j.slice(0),n=[]];for(j=i;j<4*i+28;j++){p=o[j-1];if(0===j%i||8===i&&4===j%i){p=l[p>>>24]<<24^l[p>>16&255]<<16^l[p>>8&255]<<8^l[p&255],0===j%i&&(p=p<<8^p>>>24^k<<24,k=k<<1^283*(k>>7))}o[j]=o[j-i]^p}for(i=0;j;i++,j--){p=o[i&3?j:j-4],n[i]=4>=j||4>i?p:m[0][l[p>>>24]]^m[1][l[p>>16&255]]^m[2][l[p>>8&255]]^m[3][l[p&255]]}};sjcl.cipher.aes.prototype={encrypt:function(b){return y(this,b,0)},decrypt:function(b){return y(this,b,1)},i:[[[],[],[],[],[]],[[],[],[],[],[]]],v:function(){var R=this.i[0],Q=this.i[1],P=R[4],O=Q[4],N,w,x,v=[],u=[],s,i,o,j;for(N=0;256>N;N++){u[(v[N]=N<<1^283*(N>>7))^N]=N}for(w=x=0;!P[w];w^=s||1,x=u[x]||1){o=x^x<<1^x<<2^x<<3^x<<4;o=o>>8^o&255^99;P[w]=o;O[o]=w;i=v[N=v[s=v[w]]];j=16843009*i^65537*N^257*s^16843008*w;i=257*v[o]^16843008*o;for(N=0;4>N;N++){R[N][w]=i=i<<24^i>>>8,Q[N][o]=j=j<<24^j>>>8}}for(N=0;5>N;N++){R[N]=R[N].slice(0),Q[N]=Q[N].slice(0)}}};function y(ab,aa,Z){4!==aa.length&&q(new sjcl.exception.invalid("invalid aes block size"));var Y=ab.b[Z],X=aa[0]^Y[0],V=aa[Z?3:1]^Y[1],W=aa[2]^Y[2];aa=aa[Z?1:3]^Y[3];var U,T,S,P=Y.length/4-2,R,Q=4,o=[0,0,0,0];U=ab.i[Z];ab=U[0];var O=U[1],N=U[2],j=U[3],i=U[4];for(R=0;R<P;R++){U=ab[X>>>24]^O[V>>16&255]^N[W>>8&255]^j[aa&255]^Y[Q],T=ab[V>>>24]^O[W>>16&255]^N[aa>>8&255]^j[X&255]^Y[Q+1],S=ab[W>>>24]^O[aa>>16&255]^N[X>>8&255]^j[V&255]^Y[Q+2],aa=ab[aa>>>24]^O[X>>16&255]^N[V>>8&255]^j[W&255]^Y[Q+3],Q+=4,X=U,V=T,W=S}for(R=0;4>R;R++){o[Z?3&-R:R]=i[X>>>24]<<24^i[V>>16&255]<<16^i[W>>8&255]<<8^i[aa&255]^Y[Q++],U=X,X=V,V=W,W=aa,aa=U}return o}sjcl.bitArray={bitSlice:function(e,d,f){e=sjcl.bitArray.K(e.slice(d/32),32-(d&31)).slice(1);return f===r?e:sjcl.bitArray.clamp(e,f-d)},extract:function(f,e,h){var g=Math.floor(-e-h&31);return((e+h-1^e)&-32?f[e/32|0]<<32-g^f[e/32+1|0]>>>g:f[e/32|0]>>>g)&(1<<h)-1},concat:function(f,e){if(0===f.length||0===e.length){return f.concat(e)}var h=f[f.length-1],g=sjcl.bitArray.getPartial(h);return 32===g?f.concat(e):sjcl.bitArray.K(e,g,h|0,f.slice(0,f.length-1))},bitLength:function(d){var c=d.length;return 0===c?0:32*(c-1)+sjcl.bitArray.getPartial(d[c-1])},clamp:function(e,d){if(32*e.length<d){return e}e=e.slice(0,Math.ceil(d/32));var f=e.length;d&=31;0<f&&d&&(e[f-1]=sjcl.bitArray.partial(d,e[f-1]&2147483648>>d-1,1));return e},partial:function(e,d,f){return 32===e?d:(f?d|0:d<<32-e)+1099511627776*e},getPartial:function(b){return Math.round(b/1099511627776)||32},equal:function(f,e){if(sjcl.bitArray.bitLength(f)!==sjcl.bitArray.bitLength(e)){return t}var h=0,g;for(g=0;g<f.length;g++){h|=f[g]^e[g]}return 0===h},K:function(g,f,j,i){var h;h=0;for(i===r&&(i=[]);32<=f;f-=32){i.push(j),j=0}if(0===f){return i.concat(g)}for(h=0;h<g.length;h++){i.push(j|g[h]>>>f),j=g[h]<<32-f}h=g.length?g[g.length-1]:0;g=sjcl.bitArray.getPartial(h);i.push(sjcl.bitArray.partial(f+g&31,32<f+g?j:i.pop(),1));return i},M:function(d,c){return[d[0]^c[0],d[1]^c[1],d[2]^c[2],d[3]^c[3]]}};sjcl.codec.utf8String={fromBits:function(g){var f="",j=sjcl.bitArray.bitLength(g),i,h;for(i=0;i<j/8;i++){0===(i&3)&&(h=g[i/4]),f+=String.fromCharCode(h>>>24),h<<=8}return decodeURIComponent(escape(f))},toBits:function(f){f=unescape(encodeURIComponent(f));var e=[],h,g=0;for(h=0;h<f.length;h++){g=g<<8|f.charCodeAt(h),3===(h&3)&&(e.push(g),g=0)}h&3&&e.push(sjcl.bitArray.partial(8*(h&3),g));return e}};sjcl.codec.base64={C:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",fromBits:function(j,i,p){var o="",n=0,l=sjcl.codec.base64.C,m=0,k=sjcl.bitArray.bitLength(j);p&&(l=l.substr(0,62)+"-_");for(p=0;6*o.length<k;){o+=l.charAt((m^j[p]>>>n)>>>26),6>n?(m=j[p]<<6-n,n+=26,p++):(m<<=6,n-=6)}for(;o.length&3&&!i;){o+="="}return o},toBits:function(j,i){j=j.replace(/\s|=/g,"");var p=[],o,n=0,l=sjcl.codec.base64.C,m=0,k;i&&(l=l.substr(0,62)+"-_");for(o=0;o<j.length;o++){k=l.indexOf(j.charAt(o)),0>k&&q(new sjcl.exception.invalid("this isn't base64!")),26<n?(n-=26,p.push(m^k>>>n),m=k<<32-n):(n+=6,m^=k<<32-n)}n&56&&p.push(sjcl.bitArray.partial(n&56,m,1));return p}};sjcl.codec.base64url={fromBits:function(b){return sjcl.codec.base64.fromBits(b,1,1)},toBits:function(b){return sjcl.codec.base64.toBits(b,1)}};sjcl.codec.bytes={fromBits:function(g){var f=[],j=sjcl.bitArray.bitLength(g),i,h;for(i=0;i<j/8;i++){0===(i&3)&&(h=g[i/4]),f.push(h>>>24),h<<=8}return f},toBits:function(f){var e=[],h,g=0;for(h=0;h<f.length;h++){g=g<<8|f[h],3===(h&3)&&(e.push(g),g=0)}h&3&&e.push(sjcl.bitArray.partial(8*(h&3),g));return e}};sjcl.hash.sha256=function(b){this.b[0]||this.v();b?(this.n=b.n.slice(0),this.l=b.l.slice(0),this.f=b.f):this.reset()};sjcl.hash.sha256.hash=function(b){return(new sjcl.hash.sha256).update(b).finalize()};sjcl.hash.sha256.prototype={blockSize:512,reset:function(){this.n=this.I.slice(0);this.l=[];this.f=0;return this},update:function(e){"string"===typeof e&&(e=sjcl.codec.utf8String.toBits(e));var d,f=this.l=sjcl.bitArray.concat(this.l,e);d=this.f;e=this.f=d+sjcl.bitArray.bitLength(e);for(d=512+d&-512;d<=e;d+=512){z(this,f.splice(0,16))}return this},finalize:function(){var e,d=this.l,f=this.n,d=sjcl.bitArray.concat(d,[sjcl.bitArray.partial(1,1)]);for(e=d.length+2;e&15;e++){d.push(0)
14
+ }d.push(Math.floor(this.f/4294967296));for(d.push(this.f|0);d.length;){z(this,d.splice(0,16))}this.reset();return f},I:[],b:[],v:function(){function f(b){return 4294967296*(b-Math.floor(b))|0}var e=0,h=2,g;f:for(;64>e;h++){for(g=2;g*g<=h;g++){if(0===h%g){continue f}}8>e&&(this.I[e]=f(Math.pow(h,0.5)));this.b[e]=f(Math.pow(h,1/3));e++}}};function z(U,T){var S,R,Q,O=T.slice(0),P=U.n,N=U.b,x=P[0],w=P[1],i=P[2],o=P[3],j=P[4],V=P[5],X=P[6],W=P[7];for(S=0;64>S;S++){16>S?R=O[S]:(R=O[S+1&15],Q=O[S+14&15],R=O[S&15]=(R>>>7^R>>>18^R>>>3^R<<25^R<<14)+(Q>>>17^Q>>>19^Q>>>10^Q<<15^Q<<13)+O[S&15]+O[S+9&15]|0),R=R+W+(j>>>6^j>>>11^j>>>25^j<<26^j<<21^j<<7)+(X^j&(V^X))+N[S],W=X,X=V,V=j,j=o+R|0,o=i,i=w,w=x,x=R+(w&i^o&(w^i))+(w>>>2^w>>>13^w>>>22^w<<30^w<<19^w<<10)|0}P[0]=P[0]+x|0;P[1]=P[1]+w|0;P[2]=P[2]+i|0;P[3]=P[3]+o|0;P[4]=P[4]+j|0;P[5]=P[5]+V|0;P[6]=P[6]+X|0;P[7]=P[7]+W|0}sjcl.mode.ccm={name:"ccm",encrypt:function(w,v,u,s,p){var n,o=v.slice(0),m=sjcl.bitArray,j=m.bitLength(u)/8,i=m.bitLength(o)/8;p=p||64;s=s||[];7>j&&q(new sjcl.exception.invalid("ccm: iv must be at least 7 bytes"));for(n=2;4>n&&i>>>8*n;n++){}n<15-j&&(n=15-j);u=m.clamp(u,8*(15-n));v=sjcl.mode.ccm.F(w,v,u,s,p,n);o=sjcl.mode.ccm.G(w,o,u,v,p,n);return m.concat(o.data,o.tag)},decrypt:function(w,v,u,s,p){p=p||64;s=s||[];var n=sjcl.bitArray,o=n.bitLength(u)/8,m=n.bitLength(v),j=n.clamp(v,m-p),i=n.bitSlice(v,m-p),m=(m-p)/8;7>o&&q(new sjcl.exception.invalid("ccm: iv must be at least 7 bytes"));for(v=2;4>v&&m>>>8*v;v++){}v<15-o&&(v=15-o);u=n.clamp(u,8*(15-v));j=sjcl.mode.ccm.G(w,j,u,i,p,v);w=sjcl.mode.ccm.F(w,j.data,u,s,p,v);n.equal(j.tag,w)||q(new sjcl.exception.corrupt("ccm: tag doesn't match"));return j.data},F:function(u,s,p,o,n,l){var m=[],j=sjcl.bitArray,i=j.M;n/=8;(n%2||4>n||16<n)&&q(new sjcl.exception.invalid("ccm: invalid tag length"));(4294967295<o.length||4294967295<s.length)&&q(new sjcl.exception.bug("ccm: can't deal with 4GiB or more data"));l=[j.partial(8,(o.length?64:0)|n-2<<2|l-1)];l=j.concat(l,p);l[3]|=j.bitLength(s)/8;l=u.encrypt(l);if(o.length){p=j.bitLength(o)/8;65279>=p?m=[j.partial(16,p)]:4294967295>=p&&(m=j.concat([j.partial(16,65534)],[p]));m=j.concat(m,o);for(o=0;o<m.length;o+=4){l=u.encrypt(i(l,m.slice(o,o+4).concat([0,0,0])))}}for(o=0;o<s.length;o+=4){l=u.encrypt(i(l,s.slice(o,o+4).concat([0,0,0])))}return j.clamp(l,8*n)},G:function(w,v,u,s,p,n){var o,m=sjcl.bitArray;o=m.M;var j=v.length,i=m.bitLength(v);u=m.concat([m.partial(8,n-1)],u).concat([0,0,0]).slice(0,4);s=m.bitSlice(o(s,w.encrypt(u)),0,p);if(!j){return{tag:s,data:[]}}for(o=0;o<j;o+=4){u[3]++,p=w.encrypt(u),v[o]^=p[0],v[o+1]^=p[1],v[o+2]^=p[2],v[o+3]^=p[3]}return{tag:s,data:m.clamp(v,i)}}};sjcl.misc.hmac=function(g,f){this.H=f=f||sjcl.hash.sha256;var j=[[],[]],i,h=f.prototype.blockSize/32;this.k=[new f,new f];g.length>h&&(g=f.hash(g));for(i=0;i<h;i++){j[0][i]=g[i]^909522486,j[1][i]=g[i]^1549556828}this.k[0].update(j[0]);this.k[1].update(j[1]);this.A=new f(this.k[0])};sjcl.misc.hmac.prototype.encrypt=sjcl.misc.hmac.prototype.mac=function(b){this.L&&q(new sjcl.exception.invalid("encrypt on already updated hmac called!"));this.update(b);return this.digest(b)};sjcl.misc.hmac.prototype.reset=function(){this.A=new this.H(this.k[0]);this.L=t};sjcl.misc.hmac.prototype.update=function(b){this.L=!0;this.A.update(b)};sjcl.misc.hmac.prototype.digest=function(){var b=this.A.finalize(),b=(new this.H(this.k[1])).update(b).finalize();this.reset();return b};sjcl.misc.pbkdf2=function(N,x,w,v,u){w=w||1000;(0>v||0>w)&&q(sjcl.exception.invalid("invalid params to pbkdf2"));"string"===typeof N&&(N=sjcl.codec.utf8String.toBits(N));"string"===typeof x&&(x=sjcl.codec.utf8String.toBits(x));u=u||sjcl.misc.hmac;N=new u(N);var o,s,n,m,j=[],i=sjcl.bitArray;for(m=1;32*j.length<(v||1);m++){u=o=N.encrypt(i.concat(x,[m]));for(s=1;s<w;s++){o=N.encrypt(o);for(n=0;n<o.length;n++){u[n]^=o[n]}}j=j.concat(u)}v&&(j=i.clamp(j,v));return j};sjcl.prng=function(b){this.c=[new sjcl.hash.sha256];this.g=[0];this.w=0;this.o={};this.u=0;this.D={};this.J=this.d=this.h=this.S=0;this.b=[0,0,0,0,0,0,0,0];this.e=[0,0,0,0];this.s=r;this.t=b;this.m=t;this.r={progress:{},seeded:{}};this.j=this.R=0;this.p=1;this.q=2;this.O=65536;this.B=[0,48,64,96,128,192,256,384,512,768,1024];this.P=30000;this.N=80};sjcl.prng.prototype={randomWords:function(i,h){var n=[],m;m=this.isReady(h);var l;m===this.j&&q(new sjcl.exception.notReady("generator isn't seeded"));if(m&this.q){m=!(m&this.p);l=[];var j=0,k;this.J=l[0]=(new Date).valueOf()+this.P;for(k=0;16>k;k++){l.push(4294967296*Math.random()|0)}for(k=0;k<this.c.length&&!(l=l.concat(this.c[k].finalize()),j+=this.g[k],this.g[k]=0,!m&&this.w&1<<k);k++){}this.w>=1<<this.c.length&&(this.c.push(new sjcl.hash.sha256),this.g.push(0));this.d-=j;j>this.h&&(this.h=j);this.w++;this.b=sjcl.hash.sha256.hash(this.b.concat(l));this.s=new sjcl.cipher.aes(this.b);for(m=0;4>m&&!(this.e[m]=this.e[m]+1|0,this.e[m]);m++){}}for(m=0;m<i;m+=4){0===(m+1)%this.O&&A(this),l=B(this),n.push(l[0],l[1],l[2],l[3])}A(this);return n.slice(0,i)},setDefaultParanoia:function(d,c){0===d&&"Setting paranoia=0 will ruin your security; use it only for testing"!==c&&q("Setting paranoia=0 will ruin your security; use it only for testing");this.t=d},addEntropy:function(u,s,p){p=p||"user";var o,n,l=(new Date).valueOf(),m=this.o[p],j=this.isReady(),i=0;o=this.D[p];o===r&&(o=this.D[p]=this.S++);m===r&&(m=this.o[p]=0);this.o[p]=(this.o[p]+1)%this.c.length;switch(typeof u){case"number":s===r&&(s=1);this.c[m].update([o,this.u++,1,s,l,1,u|0]);break;case"object":p=Object.prototype.toString.call(u);if("[object Uint32Array]"===p){n=[];for(p=0;p<u.length;p++){n.push(u[p])}u=n}else{"[object Array]"!==p&&(i=1);for(p=0;p<u.length&&!i;p++){"number"!==typeof u[p]&&(i=1)}}if(!i){if(s===r){for(p=s=0;p<u.length;p++){for(n=u[p];0<n;){s++,n>>>=1}}}this.c[m].update([o,this.u++,2,s,l,u.length].concat(u))}break;case"string":s===r&&(s=u.length);this.c[m].update([o,this.u++,3,s,l,u.length]);this.c[m].update(u);break;default:i=1}i&&q(new sjcl.exception.bug("random: addEntropy only supports number, array of numbers or string"));this.g[m]+=s;this.d+=s;j===this.j&&(this.isReady()!==this.j&&C("seeded",Math.max(this.h,this.d)),C("progress",this.getProgress()))},isReady:function(b){b=this.B[b!==r?b:this.t];return this.h&&this.h>=b?this.g[0]>this.N&&(new Date).valueOf()>this.J?this.q|this.p:this.p:this.d>=b?this.q|this.j:this.j},getProgress:function(b){b=this.B[b?b:this.t];return this.h>=b?1:this.d>b?1:this.d/b},startCollectors:function(){this.m||(this.a={loadTimeCollector:D(this,this.U),mouseCollector:D(this,this.V),keyboardCollector:D(this,this.T),accelerometerCollector:D(this,this.Q)},window.addEventListener?(window.addEventListener("load",this.a.loadTimeCollector,t),window.addEventListener("mousemove",this.a.mouseCollector,t),window.addEventListener("keypress",this.a.keyboardCollector,t),window.addEventListener("devicemotion",this.a.accelerometerCollector,t)):document.attachEvent?(document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector)):q(new sjcl.exception.bug("can't attach event")),this.m=!0)},stopCollectors:function(){this.m&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,t),window.removeEventListener("mousemove",this.a.mouseCollector,t),window.removeEventListener("keypress",this.a.keyboardCollector,t),window.removeEventListener("devicemotion",this.a.accelerometerCollector,t)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.m=t)},addEventListener:function(d,c){this.r[d][this.R++]=c},removeEventListener:function(h,f){var l,k,j=this.r[h],i=[];for(k in j){j.hasOwnProperty(k)&&j[k]===f&&i.push(k)}for(l=0;l<i.length;l++){k=i[l],delete j[k]}},T:function(){E(1)},V:function(b){sjcl.random.addEntropy([b.x||b.clientX||b.offsetX||0,b.y||b.clientY||b.offsetY||0],2,"mouse");E(0)},U:function(){E(2)},Q:function(d){d=d.accelerationIncludingGravity.x||d.accelerationIncludingGravity.y||d.accelerationIncludingGravity.z;if(window.orientation){var c=window.orientation;"number"===typeof c&&sjcl.random.addEntropy(c,1,"accelerometer")}d&&sjcl.random.addEntropy(d,2,"accelerometer");E(0)}};function C(g,f){var j,i=sjcl.random.r[g],h=[];for(j in i){i.hasOwnProperty(j)&&h.push(i[j])}for(j=0;j<h.length;j++){h[j](f)}}function E(b){window&&window.performance&&"function"===typeof window.performance.now?sjcl.random.addEntropy(window.performance.now(),b,"loadtime"):sjcl.random.addEntropy((new Date).valueOf(),b,"loadtime")}function A(b){b.b=B(b).concat(B(b));b.s=new sjcl.cipher.aes(b.b)}function B(d){for(var c=0;4>c&&!(d.e[c]=d.e[c]+1|0,d.e[c]);c++){}return d.s.encrypt(d.e)}function D(d,c){return function(){c.apply(d,arguments)}}sjcl.random=new sjcl.prng(6);a:try{var F,G,H,I;if(I="undefined"!==typeof module){var J;if(J=module.exports){var K;try{K=require("crypto")}catch(L){K=null}J=(G=K)&&G.randomBytes}I=J}if(I){F=G.randomBytes(128),F=new Uint32Array((new Uint8Array(F)).buffer),sjcl.random.addEntropy(F,1024,"crypto['randomBytes']")}else{if(window&&Uint32Array){H=new Uint32Array(32);if(window.crypto&&window.crypto.getRandomValues){window.crypto.getRandomValues(H)}else{if(window.msCrypto&&window.msCrypto.getRandomValues){window.msCrypto.getRandomValues(H)}else{break a}}sjcl.random.addEntropy(H,1024,"crypto['getRandomValues']")}}}catch(M){"undefined"!==typeof window&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(M))}var adyen=window.adyen=window.adyen||{};var encrypt=adyen.encrypt=adyen.encrypt||{createEncryptedForm:function(form,key,options){return new EncryptedForm(form,key,options)}};encrypt.errors=encrypt.errors||{};encrypt.errors.UNABLETOBIND="CSEB01";function addEvent(element,event,callback,capture){if(typeof element.addEventListener==="function"){element.addEventListener(event,callback,capture)}else{if(element.attachEvent){element.attachEvent("on"+event,callback)}else{throw new Error(encrypt.errors.UNABLETOBIND+": Unable to bind "+event+"-event")}}}function hasClass(elem,className){return elem&&new RegExp(" "+className+" ").test(" "+(elem.className||"")+" ")}function addClass(elem,className){if(!elem){return}if(!hasClass(elem,className)){elem.className+=" "+className}}function removeClass(elem,className){if(!elem){return}var newClass=" "+elem.className.replace(/[\t\r\n]/g," ")+" ";if(hasClass(elem,className)){while(newClass.indexOf(" "+className+" ")>=0){newClass=newClass.replace(" "+className+" "," ")}elem.className=newClass.replace(/^\s+|\s+$/g,"")}}function getAttribute(node,attribute,defaultValue){if(node&&node.getAttribute){return node.getAttribute(attribute)||defaultValue}else{return defaultValue}}encrypt.version="0_1_7";if(!Function.prototype.bind){Function.prototype.bind=function(oThis){if(typeof this!=="function"){throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable")}var aArgs=Array.prototype.slice.call(arguments,1),fToBind=this,fNOP=function(){},fBound=function(){return fToBind.apply(this instanceof fNOP&&oThis?this:oThis,aArgs.concat(Array.prototype.slice.call(arguments)))};fNOP.prototype=this.prototype;fBound.prototype=new fNOP();return fBound}}if(!Date.prototype.toISOString){(function(){function pad(number){if(number<10){return"0"+number}return number}Date.prototype.toISOString=function(){return this.getUTCFullYear()+"-"+pad(this.getUTCMonth()+1)+"-"+pad(this.getUTCDate())+"T"+pad(this.getUTCHours())+":"+pad(this.getUTCMinutes())+":"+pad(this.getUTCSeconds())+"."+(this.getUTCMilliseconds()/1000).toFixed(3).slice(2,5)+"Z"}}())}var validations={};validations.luhnCheck=function(){var argv=arguments;var argc=arguments.length;var CardNumber=argc>0?argv[0]:this.cardnumber;if(isNaN(parseInt(CardNumber,10))){return false}var no_digit=CardNumber.length;var oddoeven=no_digit&1;var sum=0;for(var count=0;count<no_digit;count++){var digit=parseInt(CardNumber.charAt(count),10);if(!((count&1)^oddoeven)){digit*=2;if(digit>9){digit-=9}}sum+=digit}if(sum%10===0){return true}else{return false}};validations.cvcCheck=function(val){return val&&val.match&&val.match(/^\d{3,4}$/)};validations.createChangeHandler=function(cse,type,allowEmpty){return function(ev){var node=ev.target||ev.srcElement,val=(node||{}).value||"",field=getAttribute(node,"data-encrypted-name");if(cse.options[field+"IgnoreNonNumeric"]){val=val.replace(/\D/g,"")}if(validations[type+"Check"](val)){cse.validity[type]=true;removeClass(node,"invalid-"+type);addClass(node,"valid-"+type)}else{cse.validity[type]=false;addClass(node,"invalid-"+type);removeClass(node,"valid-"+type)}if(allowEmpty&&val===""){removeClass(node,"valid-"+type);removeClass(node,"invalid-"+type)}cse.toggleSubmit()}};var EncryptedForm=encrypt.EncryptedForm=function(element,key,options){try{sjcl.random.startCollectors()}catch(e){}if(typeof element!=="object"||typeof element.ownerDocument!=="object"){throw new Error("Expected target element to be a HTML Form element")}if("form"!==(element.nodeName||element.tagName||"").toLowerCase()){throw new Error("Expected target element to be a HTML Form element")}this.element=element;this.key=key;this.validity={};this.options=options=options||{};if(typeof options!=="object"){throw new Error("Expected options to be an object")}if(typeof options.numberIgnoreNonNumeric==="undefined"){options.numberIgnoreNonNumeric=true}this.name=options.name||"adyen-encrypted-data";this.onsubmit=options.onsubmit||function(){};if(this.element.addEventListener){this.element.addEventListener("submit",this.handleSubmit.bind(this),false)}else{if(this.element.attachEvent){this.element.attachEvent("onsubmit",this.handleSubmit.bind(this))}}if(options.enableValidations!==false){this.addValidations()}};EncryptedForm.prototype={constructor:EncryptedForm,hasAttribute:document.documentElement.hasAttribute?function(node,attrName){return node.hasAttribute(attrName)}:function(node,attrName){return node.attributes&&node.attributes[attrName]},handleSubmit:function(e){if(this.options.enableValidations!==false){if(!this.isValid()){if(e.preventDefault){e.preventDefault()}if(window.event){window.event.returnValue=false}if(e.originalEvent){e.originalEvent.returnValue=false}e.returnValue=false;return false}}this.createEncryptedField(this.encrypt());this.onsubmit(e)},createRSAKey:function(){var k=this.key.split("|");if(k.length!=2){throw"Malformed public key"}var exp=k[0];var mod=k[1];var rsa=new RSAKey();rsa.setPublic(mod,exp);return rsa},createAESKey:function(){return new AESKey()},getEncryptedFields:function(node,fields){if(node.querySelectorAll){return node.querySelectorAll("[data-encrypted-name]")}fields=fields||[];var children=node.children;var child;for(var i=0;i<children.length;i++){child=children[i];if(this.hasAttribute(child,"data-encrypted-name")){fields.push(child)}else{this.getEncryptedFields(child,fields)}}return fields},toJSON:function(fields){var field;var data={};var key,value;for(var i=fields.length-1;i>=0;i--){field=fields[i];field.removeAttribute("name");key=field.getAttribute("data-encrypted-name");value=field.value;data[key]=value}return data},encrypt:function(){var data=this.toJSON(this.getEncryptedFields(this.element));var rsa,aes,cipher,encoded,encrypted,prefix;rsa=this.createRSAKey();aes=this.createAESKey();cipher=aes.encrypt(JSON.stringify(data));keybytes=sjcl.codec.bytes.fromBits(aes.key);encrypted=rsa.encrypt_b64(keybytes);prefix="adyenjs_"+encrypt.version+"$";return[prefix,encrypted,"$",cipher].join("")},createEncryptedField:function(data){var element=document.getElementById(this.name);if(!element){element=document.createElement("input");element.type="hidden";element.name=element.id=this.name;this.element.appendChild(element)}element.setAttribute("value",data)},addValidations:function(){var cse=this,elements=this.element.elements,c=elements.length,element,handlers={};for(;c-->0;){element=elements[c];if(!element||!element.getAttribute){continue}else{if(element.getAttribute("data-encrypted-name")==="number"){handlers.luhnHandler=handlers.luhnHandler||validations.createChangeHandler(cse,"luhn",true);addEvent(element,"change",handlers.luhnHandler,false);handlers.luhnHandler({target:element})}else{if(element.getAttribute("data-encrypted-name")==="cvc"){handlers.cvcHandler=handlers.cvcHandler||validations.createChangeHandler(cse,"cvc",true);addEvent(element,"change",handlers.cvcHandler,false);handlers.cvcHandler({target:element})}}}}},isValid:function(){var valid=true,elements=this.element.elements,enabled;for(var i in this.validity){if(this.validity.hasOwnProperty(i)){valid=valid&&this.validity[i]}}return valid},toggleSubmit:function(){var valid=this.isValid(),elements=this.element.elements,enabled;enabled=valid===true||(this.options&&this.options.submitButtonAlwaysEnabled===true);for(var c=elements.length;c-->0;){if(elements[c]&&(elements[c].type||"").toLowerCase()==="submit"){elements[c].disabled=!enabled}}return valid}};var AESKey=function(){};AESKey.prototype={constructor:AESKey,key:sjcl.random.randomWords(8,0),encrypt:function(text){return this.encryptWithIv(text,sjcl.random.randomWords(3,0))},encryptWithIv:function(text,iv){var aes,bits,cipher,cipherIV;aes=new sjcl.cipher.aes(this.key);bits=sjcl.codec.utf8String.toBits(text);cipher=sjcl.mode.ccm.encrypt(aes,bits,iv);cipherIV=sjcl.bitArray.concat(iv,cipher);return sjcl.codec.base64.fromBits(cipherIV)}}})();
@@ -0,0 +1,20 @@
1
+ module Adyen::TestCards
2
+ VISA = {
3
+ expiry_month: '08',
4
+ expiry_year: '2018',
5
+ holder_name: 'Testy McTesterson',
6
+ number: '4111111111111111',
7
+ cvc: '737',
8
+ }
9
+
10
+ MASTERCARD_3DSECURE = {
11
+ expiry_month: '08',
12
+ expiry_year: '2018',
13
+ holder_name: 'Testy McTesterson',
14
+ number: '5212345678901234',
15
+ cvc: '737',
16
+
17
+ username: 'user',
18
+ password: 'password',
19
+ }
20
+ end
@@ -0,0 +1,7 @@
1
+ <h1> Payment authorized </h1>
2
+
3
+ <ul>
4
+ <% @attributes.each do |key, value| %>
5
+ <li> <%= key %> : <span id="<%= key %>"><%= value %></span></li>
6
+ <% end %>
7
+ </ul>
@@ -0,0 +1,20 @@
1
+ <html>
2
+ <head>
3
+ <title> HPP Payment</title>
4
+ </head>
5
+ <body>
6
+ <% hpp_client = Adyen::HPP::Client.new(:test, :testing) %>
7
+ <form action="<%= hpp_client.url %>" method="post">
8
+ <p> Price: <strong>EUR 43.21</strong>. </p>
9
+ <p>
10
+ <%= hpp_client.new_request.hidden_fields(@payment) %>
11
+ <input type="submit" value="Pay" />
12
+ </p>
13
+ </form>
14
+
15
+ <p>If you are using the test account of this library, you will be redirected back
16
+ to <strong>example.com</strong> after you complete the payment on Adyen's hosted
17
+ payment pages. This is due to how the test account is configured.
18
+ </p>
19
+ </body>
20
+ </html>
@@ -0,0 +1,6 @@
1
+ <h1>Adyen integration test server </h1>
2
+
3
+ <ul>
4
+ <li><a href="/hpp">Pay with hosted payment platform</a></li>
5
+ <li><a href="/pay">Pay with API using client-side encyption</a></li>
6
+ </ul>
@@ -0,0 +1,36 @@
1
+ <html>
2
+ <head>
3
+ <title> Payment </title>
4
+ </head>
5
+ <body>
6
+ <form action="/pay" method="post" id="adyen-encrypted-form">
7
+ <p> Price: <strong>EUR 12.34</strong>. </p>
8
+ <p>
9
+ Card: <input type="text" name="card[number]" id="adyen-encrypted-form-number"
10
+ autocomplete="off" data-encrypted-name="number" /><br />
11
+ Holder name: <input type="text" name="card[holder_name]" id="adyen-encrypted-form-holder-name"
12
+ autocomplete="off" data-encrypted-name="holderName" /><br />
13
+ Expiry month: <input type="text" name="card[expiry_month]" id="adyen-encrypted-form-expiry-month"
14
+ size="2" autocomplete="off" data-encrypted-name="expiryMonth" /><br />
15
+ Expiry year: <input type="text" name="card[expiry_year]" id="adyen-encrypted-form-expiry-year"
16
+ size="4" autocomplete="off" data-encrypted-name="expiryYear" /><br />
17
+ CVC: <input type="text" name="card[cvc]" id="adyen-encrypted-form-cvc"
18
+ size="4" autocomplete="off" data-encrypted-name="cvc" /><br />
19
+ </p>
20
+ <p>
21
+ <input type="hidden" id="adyen-encrypted-form-expiry-generationtime"
22
+ value="<%= Time.now.utc.strftime('%FT%T.%3NZ') %>" data-encrypted-name="generationtime" />
23
+
24
+ <input type="submit" name="submit" value="Pay" />
25
+ </p>
26
+ </form>
27
+
28
+ <script type="text/javascript" src="/adyen.encrypt.js?0_1_7"></script>
29
+ <script type="text/javascript">
30
+ var key = "<%= Adyen.configuration.cse_public_key %>";
31
+ var options = {};
32
+
33
+ adyen.encrypt.createEncryptedForm(document.getElementById('adyen-encrypted-form'), key, options);
34
+ </script>
35
+ </body>
36
+ </html>
@@ -0,0 +1,18 @@
1
+ <html>
2
+ <body>
3
+ <form method="POST" action="<%= @issuer_url %>" id="3dform">
4
+ <input type="hidden" name="PaReq" value="<%= @pa_request %>" />
5
+ <input type="hidden" name="TermUrl" value="<%= @term_url %>" />
6
+ <input type="hidden" name="MD" value="<%= @md %>" />
7
+ <h1>Processing your 3-D Secure Transaction </h1>
8
+ <p>Please click continue to continue the processing of your 3-D Secure transaction.</p>
9
+ <input type="submit" class="button" value="continue" />
10
+ </form>
11
+
12
+ <script type="text/javascript">
13
+ window.onload = function() {
14
+ document.getElementById('3dform').submit();
15
+ }
16
+ </script>
17
+ </body>
18
+ </html>
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+ require 'adyen/hpp/signature'
3
+
4
+ class HPPSignatureTest < Minitest::Test
5
+ def setup
6
+ # values from https://docs.adyen.com/pages/viewpage.action?pageId=5376964
7
+ @shared_secret = "4468D9782DEF54FCD706C9100C71EC43932B1EBC2ACF6BA0560C05AAA7550C48"
8
+
9
+ @expected_sig = 'GJ1asjR5VmkvihDJxCd8yE2DGYOKwWwJCBiV3R51NFg='
10
+
11
+ @raw_params = {
12
+ 'merchantAccount' => 'TestMerchant',
13
+ 'currencyCode' => 'EUR',
14
+ 'paymentAmount' => '199',
15
+ 'sessionValidity' => '2015-06-25T10:31:06Z',
16
+ 'shipBeforeDate' => '2015-07-01',
17
+ 'shopperLocale' => 'en_GB',
18
+ 'merchantReference' => 'SKINTEST-1435226439255',
19
+ 'skinCode' => 'X7hsNDWp',
20
+ }
21
+ end
22
+
23
+ def test_sign
24
+ signed_params = Adyen::HPP::Signature.sign(@raw_params, @shared_secret)
25
+ assert_equal @expected_sig, signed_params['merchantSig']
26
+ end
27
+
28
+ def test_verify_succeeds_with_same_secret
29
+ signed_params = @raw_params.merge('merchantSig' => @expected_sig)
30
+ assert_equal true, Adyen::HPP::Signature.verify(signed_params, @shared_secret)
31
+ end
32
+
33
+ def test_verification_fails_with_different_secret
34
+ signed_params = @raw_params.merge('merchantSig' => @expected_sig)
35
+ assert_equal false, Adyen::HPP::Signature.verify(signed_params, '12345')
36
+ end
37
+ end
data/test/hpp_test.rb ADDED
@@ -0,0 +1,250 @@
1
+ require 'test_helper'
2
+ require 'adyen/hpp'
3
+
4
+ class HppTest < Minitest::Test
5
+ include Adyen::Matchers
6
+ include Adyen::Test::EachXMLBackend
7
+
8
+ def setup
9
+ @skin_code1 = 'abcdefgh'
10
+ @skin_code2 = 'ijklmnop'
11
+ @shared_secret_skin1 = '4468D9782DEF54FCD706C9100C71EC43932B1EBC2ACF6BA0560C05AAA7550C48'
12
+ @shared_secret_skin2 = '21F58626031F08A30F6BD07BB8AC12C19B56F6C99C6E1DA991A52A1C64A4C010'
13
+
14
+ Adyen.configuration.default_form_params[:merchant_account] = 'TestMerchant'
15
+ Adyen.configuration.register_form_skin(:skin1, @skin_code1, @shared_secret_skin1)
16
+ Adyen.configuration.register_form_skin(:skin2, @skin_code2, @shared_secret_skin2, merchant_account: 'OtherMerchant')
17
+
18
+ # Use autodetection for the environment unless otherwise specified
19
+ Adyen.configuration.environment = nil
20
+ Adyen.configuration.payment_flow = :select
21
+ Adyen.configuration.payment_flow_domain = nil
22
+ Adyen.configuration.default_skin = :skin1
23
+
24
+ @payment_attributes = {
25
+ :currency_code => 'GBP',
26
+ :payment_amount => 10000,
27
+ :merchant_reference => 'Internet Order 12345',
28
+ :ship_before_date => '2007-10-20',
29
+ :session_validity => '2007-10-11T11:00:00Z',
30
+ :billing_address => {
31
+ :street => 'Alexanderplatz',
32
+ :house_number_or_name => '0815',
33
+ :city => 'Berlin',
34
+ :postal_code => '10119',
35
+ :state_or_province => 'Berlin',
36
+ :country => 'Germany',
37
+ },
38
+ :shopper => {
39
+ :telephone_number => '1234512345',
40
+ :first_name => 'John',
41
+ :last_name => 'Doe',
42
+ :social_security_number => '123-45-1234'
43
+ }
44
+ }
45
+
46
+ @recurring_payment_attributes = @payment_attributes.merge(
47
+ :recurring_contract => 'DEFAULT',
48
+ :shopper_reference => 'grasshopper52',
49
+ :shopper_email => 'gras.shopper@somewhere.org'
50
+ )
51
+ end
52
+
53
+ def test_autodetected_redirect_url
54
+ request = Adyen::HPP::Request.new(@payment_attributes)
55
+ assert_equal 'https://test.adyen.com/hpp/select.shtml', request.url
56
+
57
+ Adyen.configuration.stubs(:autodetect_environment).returns('live')
58
+ assert_equal 'https://live.adyen.com/hpp/select.shtml', request.url
59
+ end
60
+
61
+ def test_explicit_redirect_url
62
+ assert_equal 'https://test.adyen.com/hpp/select.shtml',
63
+ Adyen::HPP::Request.new(@payment_attributes, skin: :skin1, environment: :test).url
64
+ assert_equal 'https://live.adyen.com/hpp/select.shtml',
65
+ Adyen::HPP::Request.new(@payment_attributes, skin: :skin1, environment: :live).url
66
+ assert_equal 'https://test.adyen.com/hpp/select.shtml',
67
+ Adyen::HPP::Request.new(@payment_attributes, skin: :skin2, environment: :test).url
68
+ assert_equal 'https://live.adyen.com/hpp/select.shtml',
69
+ Adyen::HPP::Request.new(@payment_attributes, skin: :skin2, environment: :live).url
70
+ assert_equal 'https://test.adyen.com/hpp/select.shtml',
71
+ Adyen::HPP::Request.new(@payment_attributes, environment: :test).url
72
+ assert_equal 'https://live.adyen.com/hpp/select.shtml',
73
+ Adyen::HPP::Request.new(@payment_attributes, environment: :live).url
74
+ end
75
+
76
+ def test_redirect_url_for_different_payment_flows
77
+ request = Adyen::HPP::Request.new(@payment_attributes, environment: :test)
78
+
79
+ Adyen.configuration.payment_flow = :select
80
+ assert_equal 'https://test.adyen.com/hpp/select.shtml', request.url
81
+
82
+ Adyen.configuration.payment_flow = :pay
83
+ assert_equal 'https://test.adyen.com/hpp/pay.shtml', request.url
84
+
85
+ Adyen.configuration.payment_flow = :details
86
+ assert_equal 'https://test.adyen.com/hpp/details.shtml', request.url
87
+ end
88
+
89
+ def test_redirect_url_for_custom_domain
90
+ request = Adyen::HPP::Request.new(@payment_attributes, environment: :test)
91
+
92
+ Adyen.configuration.payment_flow_domain = "checkout.mydomain.com"
93
+ assert_equal 'https://checkout.mydomain.com/hpp/select.shtml', request.url
94
+ end
95
+
96
+ def test_redirect_url_generation
97
+ attributes = {
98
+ :currency_code => 'GBP', :payment_amount => 10000, :ship_before_date => Date.parse('2015-10-26'),
99
+ :merchant_reference => 'Internet Order 12345', :session_validity => Time.parse('2015-10-26 10:30')
100
+ }
101
+
102
+ request = Adyen::HPP::Request.new(attributes)
103
+
104
+ processed_attributes = {
105
+ 'currencyCode' => 'GBP', 'paymentAmount' => '10000', 'shipBeforeDate' => '2015-10-26',
106
+ 'merchantReference' => 'Internet Order 12345', 'sessionValidity' => '2015-10-26T10:30:00Z',
107
+ 'merchantAccount' => 'TestMerchant', 'skinCode' => @skin_code1, 'merchantSig' => 'ewDgqa+m3rMO6MOZfQ0ugWdwsu+otvRVBVujqGfgvb8='
108
+ }
109
+
110
+ redirect_uri = URI(request.redirect_url)
111
+ assert_match %r[^#{request.url}], redirect_uri.to_s
112
+
113
+ params = CGI.parse(redirect_uri.query)
114
+ processed_attributes.each do |key, value|
115
+ assert_equal value, params[key].first
116
+ end
117
+ end
118
+
119
+ def test_redirect_url_generation_explicit_skin_code_and_shared_secret
120
+ attributes = {
121
+ :currency_code => 'GBP', :payment_amount => 10000, :ship_before_date => Date.parse('2015-10-26'),
122
+ :merchant_reference => 'Internet Order 12345', :session_validity => Time.parse('2015-10-26 10:30'),
123
+ :skin_code => @skin_code1
124
+ }
125
+
126
+ request = Adyen::HPP::Request.new(attributes, shared_secret: @shared_secret_skin1)
127
+
128
+ processed_attributes = {
129
+ 'currencyCode' => 'GBP', 'paymentAmount' => '10000', 'shipBeforeDate' => '2015-10-26',
130
+ 'merchantReference' => 'Internet Order 12345', 'sessionValidity' => '2015-10-26T10:30:00Z',
131
+ 'merchantAccount' => 'TestMerchant', 'skinCode' => @skin_code1, 'merchantSig' => 'ewDgqa+m3rMO6MOZfQ0ugWdwsu+otvRVBVujqGfgvb8='
132
+ }
133
+
134
+ redirect_uri = URI(request.redirect_url)
135
+ assert_match %r[^#{request.url}], redirect_uri.to_s
136
+
137
+ params = CGI.parse(redirect_uri.query)
138
+ processed_attributes.each do |key, value|
139
+ assert_equal value, params[key].first
140
+ end
141
+ end
142
+
143
+ def test_redirect_url_generation_with_direct_skin_details
144
+ attributes = {
145
+ :currency_code => 'GBP', :payment_amount => 10000, :ship_before_date => Date.parse('2015-10-26'),
146
+ :merchant_reference => 'Internet Order 12345', :session_validity => Time.parse('2015-10-26 10:30'),
147
+ :merchant_account => 'OtherMerchant'
148
+ }
149
+
150
+ request = Adyen::HPP::Request.new(attributes, skin: :skin2)
151
+
152
+ processed_attributes = {
153
+ 'currencyCode' => 'GBP', 'paymentAmount' => '10000', 'shipBeforeDate' => '2015-10-26',
154
+ 'merchantReference' => 'Internet Order 12345', 'sessionValidity' => '2015-10-26T10:30:00Z',
155
+ 'merchantAccount' => 'OtherMerchant', 'skinCode' => @skin_code2, 'merchantSig' => 'uS/tdqapxD8rQKBRzKQ9wOIiOFRmcOR3HsC8CO15Zto='
156
+ }
157
+
158
+ redirect_uri = URI(request.redirect_url)
159
+ assert_match %r[^#{request.url}], redirect_uri.to_s
160
+
161
+ params = CGI.parse(redirect_uri.query)
162
+ processed_attributes.each do |key, value|
163
+ assert_equal value, params[key].first
164
+ end
165
+ end
166
+
167
+ def test_payment_methods_url_generation
168
+ attributes = {
169
+ :currency_code => 'GBP', :payment_amount => 10000, :ship_before_date => Date.parse('2015-10-26'),
170
+ :merchant_reference => 'Internet Order 12345', :session_validity => Time.parse('2015-10-26 10:30')
171
+ }
172
+
173
+ request = Adyen::HPP::Request.new(attributes)
174
+
175
+ processed_attributes = {
176
+ 'currencyCode' => 'GBP', 'paymentAmount' => '10000', 'shipBeforeDate' => '2015-10-26',
177
+ 'merchantReference' => 'Internet Order 12345', 'sessionValidity' => '2015-10-26T10:30:00Z',
178
+ 'merchantAccount' => 'TestMerchant', 'skinCode' => @skin_code1, 'merchantSig' => 'ewDgqa+m3rMO6MOZfQ0ugWdwsu+otvRVBVujqGfgvb8='
179
+ }
180
+
181
+ payment_methods_uri = URI(request.payment_methods_url)
182
+ assert_match %r[^#{request.url(:directory)}], payment_methods_uri.to_s
183
+
184
+ params = CGI.parse(payment_methods_uri.query)
185
+ processed_attributes.each do |key, value|
186
+ assert_equal value, params[key].first
187
+ end
188
+ end
189
+
190
+ def test_has_valid_signature
191
+ params = {
192
+ 'authResult' => 'AUTHORISED', 'pspReference' => '1211992213193029',
193
+ 'merchantReference' => 'Internet Order 12345', 'skinCode' => @skin_code1,
194
+ 'merchantSig' => 'owrLGxBP/l5xej5VZn8FKS1exn0qOgk0P9kmRdBBw9Q='
195
+ }
196
+
197
+ correct_secret = @shared_secret_skin1
198
+ incorrect_secret = @shared_secret_skin2
199
+
200
+ assert Adyen::HPP::Response.new(params).has_valid_signature?
201
+ assert Adyen::HPP::Response.new(params, shared_secret: correct_secret).has_valid_signature?
202
+
203
+ refute Adyen::HPP::Response.new(params.merge('skinCode' => @skin_code2)).has_valid_signature?
204
+ refute Adyen::HPP::Response.new(params, shared_secret: incorrect_secret).has_valid_signature?
205
+
206
+ refute Adyen::HPP::Response.new(params.merge('pspReference' => 'tampered')).has_valid_signature?
207
+ refute Adyen::HPP::Response.new(params.merge('merchantSig' => 'tampered')).has_valid_signature?
208
+
209
+ assert_raises(ArgumentError) { Adyen::HPP::Response.new(nil).has_valid_signature? }
210
+ assert_raises(ArgumentError) { Adyen::HPP::Response.new({}).has_valid_signature? }
211
+ assert_raises(ArgumentError) { Adyen::HPP::Response.new(params.delete(:skinCode)).has_valid_signature? }
212
+ end
213
+
214
+ def test_hidden_payment_form_fields
215
+ request = Adyen::HPP::Request.new(@payment_attributes, skin: :skin1, environment: :test)
216
+
217
+ payment_snippet = <<-HTML
218
+ <form id="adyen" action="#{CGI.escapeHTML(request.url)}" method="post">
219
+ #{request.hidden_fields}
220
+ </form>
221
+ HTML
222
+
223
+ for_each_xml_backend do
224
+ assert_adyen_single_payment_form payment_snippet,
225
+ merchantAccount: 'TestMerchant',
226
+ currencyCode: 'GBP',
227
+ paymentAmount: '10000',
228
+ skinCode: @skin_code1
229
+ end
230
+ end
231
+
232
+ def test_hidden_recurring_payment_form_fields
233
+ request = Adyen::HPP::Request.new(@recurring_payment_attributes, skin: :skin2, environment: :live)
234
+
235
+ recurring_snippet = <<-HTML
236
+ <form id="adyen" action="#{CGI.escapeHTML(request.url)}" method="post">
237
+ #{request.hidden_fields}
238
+ </form>
239
+ HTML
240
+
241
+ for_each_xml_backend do
242
+ assert_adyen_recurring_payment_form recurring_snippet,
243
+ merchantAccount: 'OtherMerchant',
244
+ currencyCode: 'GBP',
245
+ paymentAmount: '10000',
246
+ recurringContract: 'DEFAULT',
247
+ skinCode: @skin_code2
248
+ end
249
+ end
250
+ end
@@ -0,0 +1,52 @@
1
+ require 'test_helper'
2
+ require 'helpers/capybara'
3
+
4
+ class HPPIntegrationTest < Minitest::Test
5
+ extend Adyen::Test::Flaky
6
+ include Capybara::DSL
7
+
8
+ flaky_test "HPP payment flow" do
9
+ page.driver.headers = {
10
+ "Accept" => "text/html;q=0.9,*/*",
11
+ "User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36" # UUID/#{SecureRandom.uuid}
12
+ }
13
+
14
+ order_uuid = "HPP #{SecureRandom.uuid}"
15
+ visit("/hpp?merchant_reference=#{CGI.escape(order_uuid)}")
16
+
17
+ click_button("Pay")
18
+
19
+ assert page.has_content?('Please select your payment method'), "Expected to arrive on Adyen's hosted payment pages."
20
+ assert_equal 'https://test.adyen.com/hpp/select.shtml', page.current_url
21
+
22
+ click_button('VISA')
23
+
24
+ assert page.has_content?('Enter your Payment Details')
25
+ assert_equal 'https://test.adyen.com/hpp/details.shtml', page.current_url
26
+
27
+ fill_in('card.cardNumber', :with => Adyen::TestCards::VISA[:number])
28
+ fill_in('card.cardHolderName', :with => Adyen::TestCards::VISA[:holder_name])
29
+ fill_in('card.cvcCode', :with => Adyen::TestCards::VISA[:cvc])
30
+ select(Adyen::TestCards::VISA[:expiry_month], :from => 'card.expiryMonth')
31
+ select(Adyen::TestCards::VISA[:expiry_year], :from => 'card.expiryYear')
32
+
33
+ click_button('continue')
34
+
35
+ assert page.has_content?('Please review and complete your payment')
36
+ assert_equal 'https://test.adyen.com/hpp/completeCard.shtml', page.current_url
37
+
38
+ click_button('pay')
39
+ follow_redirect_back
40
+
41
+ assert page.has_content?('Payment authorized')
42
+ assert_match /\A\d+\z/, find("#psp_reference").text
43
+ assert_equal order_uuid, find("#merchant_reference").text
44
+ end
45
+
46
+ def follow_redirect_back
47
+ uri = URI(page.current_url.gsub('%25', '%'))
48
+ assert_equal 'example.com', uri.host
49
+ assert_equal '/result', uri.path
50
+ visit('/hpp/result?' + uri.query)
51
+ end
52
+ end